Need help with SelectInput

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)

Can you provide a file to test the upload on?

Thanks for getting back to me.

Here's a data set that corresponds to the data in the lists. I'm sorry but I don't know a better way to send this to you.

date popln
1900 21.112
1910 27.881
1920 44.051
1930 70.278
1940 86.942
1950 136.395
1960 256.782
1970 415.387
1980 483.024
1990 545.837
2000 665.865
2010 691.893

if you want to ignore the rownames, then you need to strip the names off of this object

   base.list <-reactive(
      {
        req(t.input())
        setNames( as.list(t.input()[,1])
               NULL)
      }
    )

Thanks for your help on this. I really appreciate it.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.