How can I switch between page layouts in Shiny in response to user input? For example, I would like to switch between a sidebar layout to a wellpanel layout in order to have the graphics be able to span the entire page.
What I have so far seems to be on the verge of working, but I think the issue is that I can't reuse interfaces created from renderUI
. Here is an example,
library(shiny)
shinyApp(
shinyUI(
fluidPage(
radioButtons('layout', 'Layout:', choices=c('Sidebar', 'WellPanel'), inline=TRUE),
conditionalPanel(
condition = "input.layout == 'Sidebar'",
uiOutput('sidebarUI')
),
conditionalPanel(
condition = "input.layout == 'WellPanel'",
uiOutput('wellUI')
)
)
),
shinyServer(function(input, output) {
output$sidebarUI <- renderUI({
sidebarLayout(
sidebarPanel(
uiOutput('ui')
),
mainPanel(
plotOutput('plot')
)
)
})
output$wellUI <- renderUI({
fluidRow(
column(12, plotOutput('plot')),
column(12, wellPanel(uiOutput('ui')))
)
})
output$ui <- renderUI({
list(
checkboxInput('inp1', 'Some stuff'),
sliderInput('inp2', 'Some more stuff', 0, 10, 5)
)
})
output$plot <- renderPlot({ plot(1) })
})
)
If either one of the conditional panels is commented out, then the other one works, but only one will work with both conditional panels. How is this done?
See Question&Answers more detail:os