I'm creating a shiny app with a selectInput dynamically populated with a reactive function, created via renderUI. The selectInput is in a separate "configuration" tabpanel. I noticed that after running the App the input$id value remains NULL until I click on the tabPanel where the uiOutput() resides. Then after it is rendered, input$id is assigned with the "selected" value.
I tried to use req(input$id) where needed but it did not work. If I try running req(input$id) in the Debug console the error returned is just "Error: ". I also tried with shinydashboard but got the same behaviour.
I created a minimal reproducible example. The textOutput in the tabPanel "A" should display the choice of the selectInput. But until you clic on the second tabPanel, it shows nothing.
library(shiny)
ui <- fluidPage(
tabsetPanel(
tabPanel("one", textOutput('text')),
tabPanel("two",
uiOutput('select'))
)
)
server <- function(input, output, session) {
c <- reactive({
list("A", "B", "C")
})
output$select <- renderUI({
selectInput(
inputId = "choice",
label = "Select input",
choices = c(),
selected = 1
)
})
output$text <- renderText(
input$choice
)
}
shinyApp(ui, server)
If I directly put a selectInput in the second tabPanel (without renderUI), input$choice is initialised right from the app start
e.g.
library(shiny)
ui <- fluidPage(
tabsetPanel(
tabPanel("one", textOutput('text')),
tabPanel("two",
selectInput(
inputId = "choice",
label = "Select input",
choices = c("A", "B", "C"),
selected = 1
))
)
)
server <- function(input, output, session) {
output$text <- renderText({
input$choice
})
}
shinyApp(ui, server)
Is there any way to "initialise" the renderUI element without having to load its tabPanel?
Thanks
outputOptions(output, "choice", suspendWhenHidden = FALSE)- Ryan Morton