Skip to content

Instantly share code, notes, and snippets.

@wch
Created March 17, 2014 21:14
Show Gist options
  • Save wch/9608492 to your computer and use it in GitHub Desktop.
Save wch/9608492 to your computer and use it in GitHub Desktop.
conditionalPanel example for R Shiny
Type: Shiny
Title: conditionalPanel demo
License: MIT
Author: Winston Chang <winston@rstudio.com>
AuthorUrl: http://www.rstudio.com/
Tags: conditionalpanel
DisplayMode: Showcase
shinyServer(function(input, output) {
output$scatterPlot <- renderPlot({
x <- rnorm(input$n)
y <- rnorm(input$n)
plot(x, y)
})
})
shinyUI(fluidPage(
titlePanel("Conditional panels"),
column(4, wellPanel(
sliderInput("n", "Number of points:",
min = 10, max = 200, value = 50, step = 10)
)),
column(5,
"The plot below will be not displayed when the slider value",
"is less than 50.",
# With the conditionalPanel, the condition is a JavaScript
# expression. In these expressions, input values like
# input$n are accessed with dots, as in input.n
conditionalPanel("input.n >= 50",
plotOutput("scatterPlot", height = 300)
)
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment