I need help with SelectInput.
The enclosed code creates a two-column list, reads it into a variable(t.input), and reads the first column of t.input into two SelectInput statements. The SelectInputs list the row labels, e.g., X1900, instead of the values in the first column, e.g., 1900. When I upload the data from a .csv file I get the values, not the labels.
I need the values for later computations and would really appreciate guidance on what I'm doing wrong loading my lists.
library(tidyverse)
library(shiny)
library(lubridate)
library(ggplot2)
ui <- fluidPage(
titlePanel("What if? Trend"),
sidebarLayout(
sidebarPanel(
fileInput("upload.file", "Upload trend data file",
multiple = FALSE,
accept = ".csv"),
uiOutput("base.date.output"),
uiOutput("launch.date.output"),
# uiOutput("target.date.output"),
# textInput("limit","Enter growth limit", value = ""),
# textInput("study.area","Enter study area name", value = ""),
# textInput("variable","Enter variable label", value = ""),
),
mainPanel(
# tableOutput("t.input")
# tableOutput("date.list")
)
)
)
server <- function(input, output, session) {
# read trend data file
# t.input <- eventReactive(input$upload.file, {
# read_csv(input$upload.file$datapath)
# })
list1 <- list(1900,1910,1920,1930,
1940,1950,1960,1970
,1980,1990,2000,2010)
list1 <- as.data.frame(list1)
list1 <- t(list1)
list2 <- list(21.112,27.881,44.051,70.278,
86.942,136.395,256.782,415.387,
483.024,545.837,665.865,691.893)
list2 <- as.data.frame(list2)
list2 <- t(list2)
t.input <- reactive(cbind(list1,list2))
base.list <-reactive(
{
req(t.input())
as.list(t.input()[,1])
}
)
launch.list <- reactive(
base.list()
)
# Specify parameters ----
output$base.date.output <- renderUI({
selectInput("base.date",
label = "Select base date",
choices = base.list(),
selected = "")
})
output$launch.date.output <- renderUI({
selectInput("launch.date",
label = "Select launch date",
choices = launch.list(),
selected = "")
})
}
shinyApp(ui, server)