Skip to content

Commit

Permalink
Add namespaced conditional panel demo
Browse files Browse the repository at this point in the history
  • Loading branch information
alandipert committed Jun 21, 2017
1 parent e3e8a15 commit 2505726
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 119-namespaced-conditionalpanel-demo/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Type: Shiny
Title: Namespaced conditionalPanel demo
License: MIT
Author: Alan Dipert <[email protected]>
AuthorUrl: http://www.rstudio.com/
Tags: conditionalpanel
DisplayMode: Showcase
54 changes: 54 additions & 0 deletions 119-namespaced-conditionalpanel-demo/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
myPlotUI <- function(id, label = "My Plot") {
ns <- NS(id)
tagList(
column(4, wellPanel(
sliderInput(
ns("n"),
"Number of points:",
min = 10,
max = 200,
value = 50,
step = 10
)
)),

column(
5,
tags$h2(label),
"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",
## The condition is namespaced to this particular
## instance of this module by providing the ns parameter.
## Consequently, input.n refers to this module's input
## named n, and no other.
ns = ns,
plotOutput(ns("scatterPlot"), height = 300))
)
)
}

myPlot <- function(input, output, session, deviates) {
output$scatterPlot <- renderPlot({
x <- rnorm(input$n)
y <- rnorm(input$n)
plot(x, y)
})
}

server <- function(input, output) {
callModule(myPlot, "plot1")
callModule(myPlot, "plot2")
}

ui <- fluidPage(
titlePanel("Namespaced conditional panels"),
myPlotUI("plot1", label = "My first plot"),
myPlotUI("plot2", label = "My second plot")
)

shinyApp(ui = ui, server = server)

0 comments on commit 2505726

Please sign in to comment.