Consider the below sample application demonstrating two ways to show UI based on a condition:
library(shiny)
ui <- fluidPage(
tagList(
checkboxInput("toggle", "Toggle"),
conditionalPanel(
condition = "output.condition",
tags$p("Output from conditionalPanel")
),
uiOutput("ui")
)
)
server <- function(input, output, session) {
# conditionalPanel
output$condition <- reactive(input$toggle)
outputOptions(output, "condition", suspendWhenHidden = FALSE)
# uiOutput
output$ui <- renderUI({
req(isTRUE(input$toggle))
tags$p("Output from uiOutput")
})
}
shinyApp(ui, server)
In terms of the front-end, the conditionalPanel
and uiOutput
/req
patterns seem to behave similarly. Are there any differences, especially related to performance, that would make one pattern more beneficial?