Hi there,
I am using uiOutput in my ui code to create a selectInput based on renderUI in my server code, but I also want to use the output of the selectInput later on in my server code. How do I do this? Currently, the created selectInput is populated based on the selection in another selectInput in the ui code... For an example, see below.
I'm pretty sure this should be quite simple, but I'm not seeing it at the moment
Regards,
Will
ui <- fluidPage(
fluidRow(
column(3, tagList(
selectInput('group', 'Report group', choices = reportgroups),
uiOutput('reportdd')
)
)
)
)
server <- function(input, output) {
output$reportdd <- renderUI({
selectInput('report', 'Report', grdropdown[group==input$group, report])
})
#I want to use the value selected in the 'report' selectInput to filter some data...
qvars <- reactive({
qgroups[group==input$group & report==input$report][['bvar']]
})
}
I am not quite sure what doesn't work, what error messages are you getting? Could you provide a reproducible example?
Maybe, you need some req() statements in your renderUI() and reactive() calls just to make sure that the input variables you need for these to function properly are "truthy" - you can read about req() here: https://shiny.rstudio.com/reference/shiny/latest/req.html
Ah, yes, I think that might be it. I think what is happening is that the data.table does not have a value from input$report on which to filter until the 'report' control has been rendered. I will try req() and let you know how I get on!
After rewriting this into a reprex (below), I no longer think this makes a particularly good case study because it depends on a specific behaviour of data.table which won't be familiar to that many readers of the book.
I must admit, I have found data.table a little challenging to learn having been accustomed to data frames. It's very fast, however, which is why I wanted to use it in my app. I look forward to getting a copy of your Shiny book!