Get value from inputSelect

34 Views Asked by At

I have a selectInput which lists the column names of a dataframe. The dataframe includes a years field. When we select a column name, I create a graph representing the evolution of the column values ​​over the years. I set the first value of the colnames(df) list as default value in the selectInput.

When I launch my application, I would like the chart to be created by default with the first column. But in input$var_expl (id of selectInput) i get NULL value.

mod_dashboard.R

mod_dashboard_ui <- function(id){
  ns <- NS(id)
  tagList(
    uiOutput(ns("filter_var_expl")),
    plotOutput(ns("chart_evol"))
  )
}

mod_dashboard_server <- function(id){
  moduleServer( id, function(input, output, session){
    ns <- session$ns
    df <- as.data.frame(matrix(runif(200), nrow=10))
    df$year <- 2000:2009

    output$filter_var_expl <- renderUI({
      selectInput("var_expl", "Choose a col", choices = colnames(df),
                  selected = colnames(df)[1])
    })

    output$chart_evol <- renderPlot({
      print(input$var_expl)
      req(input$var_expl)
      ggplot(df, aes_string(x = "year", y = input$var_expl)) +
        geom_line() +
        labs(title = paste("Title"))
    })
  })
}

app_ui.R

app_ui <- function(request) { tagList( fluidPage( mod_dashboard_ui("graph") ))}

app_server.R

app_server <- function(input, output, session) { mod_dashboard_server("graph") }
0

There are 0 best solutions below