Skip to content

Instantly share code, notes, and snippets.

Created January 6, 2014 10:44
Show Gist options
  • Save anonymous/8281021 to your computer and use it in GitHub Desktop.
Save anonymous/8281021 to your computer and use it in GitHub Desktop.
how to pass a reactiveValues to conditionalPanel? First attempt, not working
# server.R
shinyServer(
function(input, output) {
values <- reactiveValues(cond = 0)
observe({
if(is.null(input$action) || input$action == 0){return()}
values$cond <- isolate(1-values$cond) # switch between 0 and 1
})
output$debug <- renderPrint({
#return(invisible())
print(paste0("values$cond = ", print(values$cond)))
print(paste0("input$action = ", print(input$action)))
})
output$plot <- renderPlot({
hist(runif(1000))
})
})
# ui.R
shinyUI(
fluidPage(
title = "conditionalPanel demo"
,
wellPanel(h5("Debug:"),textOutput("debug"))
,
actionButton(inputId = "action", label = "Something Else Please")
, br(), br()
,
wellPanel(
conditionalPanel(condition = "values.cond == 0" # pass reactiveValues values$cond
, tabsetPanel(
tabPanel("Plot1", plotOutput("plot"), value = 11)
,
tabPanel("Plot2", "Nothing Here", value = 12)
, id = "tabsetPanel1"
, selected = 11
)
)
)
,
wellPanel(
conditionalPanel(condition = "values.cond == 1" # pass reactiveValues values$cond
, tabsetPanel(
tabPanel("Something Else", "Not Much", value = 21)
,
tabPanel("Something Else Altogether", "Not Much More", value = 22)
, id = "tabsetPanel2"
, selected = 22
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment