Hi,
I have put together a reproducible example that illustrates the problem that I have with a much bigger Shiny app. So, the basic idea of the app is the following:
- the app has 2 tabs and a text box,
- content of tab #2 depends on selection made in tab #1, and
- the content of the text box depends on the selection made in the 2 tabs.
Problems:
- when the app opens, the content of the text box ignores the default content of tab #2
- the content of the text box only reflects the changes made in the currently active tab and seem to ignore the other tab...
It looks like the cascading reactivity is not happening and I would very much appreciate any suggestion to force the full reactive cascade.
Thanks
PS: I know that some coding options (including the make.txt function and the intermediary reactive objects) may be superfluous for such a little useless app, but they reflect what it happening in my more complex app. So please, ignore this, except if that is the source of my reactivity problem.
PPS: this post is a duplicate of a post to the shiny-discuss Google group
require(shiny)
require(shinydashboard)
make.txt <- function(input, table){
c(
sprintf('Choice: %s', input$choiceInput),
sprintf('Sub-choice: %s', input$subchoiceInput)
)
}
myServer <- function(input, output, session) {
#subchoiceUI
output$subchoiceUI <- renderUI({
if (input$choiceInput == 'A'){
subchoices <- paste0('a', 1:5)
} else {
subchoices <- paste0('b', 11:15)
}
selectInput(
inputId = 'subchoiceInput',
label = 'Sub choice',
choices = subchoices,
selected = subchoices[1],
width = '100%'
)
})
# text UI
mytext <- reactive({
return(make.txt(input, table))
})
output$textUI <- renderText({
paste(mytext(), collapse = '\n')
})
}
myUI <- function(){
dashboardPage(
header = dashboardHeader(
title = 'Reactivity problem'
),
sidebar = dashboardSidebar(
disable = TRUE
),
body = dashboardBody(
fluidRow(
column(
width = 6,
tabBox(
tabPanel(
title = 'Settings',
fluidRow(
column(
width = 12,
selectInput(
inputId = 'choiceInput',
label = 'Choice',
choices = c('A','B'),
selected = 'A',
width = '100%'
)
)
)
),
tabPanel(
title = 'Sub-settings',
fluidRow(
column(
width = 12,
uiOutput('subchoiceUI')
)
)
),
width = 12
)
),
column(
width = 6,
box(
width = 12,
title = 'Text box',
verbatimTextOutput('textUI')
)
)
)
)
)
}
shinyApp(ui = myUI, server = myServer)