Reputation: 14331
I have a shiny app with two related analyses. Within each analysis there are a few distinct types of results.
The interface is getting really busy and I'd like to have the output elements be collapsible (maybe like this).
Are there any examples of this type of ui
file? My current one looks like this:
shinyUI(
fluidPage(
tabsetPanel(
tabPanel("Analysis 1",
sidebarPanel(
sliderInput("value1", "some value",
min=1, max=20, value=5, step=0.2)
),
mainPanel(
## these two elements collapse together
p(textOutput("results_1_a_text")),
plotOutput("results_1_a_graph", height = "400px"),
## these two elements collapse together
p(textOutput("results_1_b_text")),
plotOutput("results_1_b_graph", height = "400px")
)
),
tabPanel("Analysis 2",
sidebarPanel(
sliderInput("value2", "some value",
min=1, max=20, value=5, step=0.2)
),
mainPanel(
## these two elements collapse together
p(textOutput("results_2_a_text")),
plotOutput("results_2_a_graph", height = "400px"),
## these two elements collapse together
p(textOutput("results_2_b_text")),
plotOutput("results_2_b_graph", height = "400px")
)
)
)
)
)
Thanks,
Max
Upvotes: 1
Views: 3735
Reputation: 29407
Have a look at the ShinyBS. Example taken from there too
library(shiny)
library(shinyBS)
shinyApp(
ui =
fluidPage(
sidebarLayout(
sidebarPanel(HTML("This button will open Panel 1 using updateCollapse."),
actionButton("p1Button", "Push Me!"),
selectInput("styleSelect", "Select style for Panel 1",
c("default", "primary", "danger", "warning", "info", "success"))
),
mainPanel(
bsCollapse(id = "collapseExample", open = "Panel 2",
bsCollapsePanel("Panel 1", "This is a panel with just text ",
"and has the default style. You can change the style in ",
"the sidebar.", style = "info"),
bsCollapsePanel("Panel 2", "This panel has a generic plot. ",
"and a 'success' style.", plotOutput("genericPlot"), style = "success")
)
)
)
),
server =
function(input, output, session) {
output$genericPlot <- renderPlot(plot(rnorm(100)))
observeEvent(input$p1Button, ({
updateCollapse(session, "collapseExample", open = "Panel 1")
}))
observeEvent(input$styleSelect, ({
updateCollapse(session, "collapseExample", style = list("Panel 1" = input$styleSelect))
}))
}
)
Upvotes: 4