-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add namespaced conditional panel demo
- Loading branch information
1 parent
e3e8a15
commit 2505726
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |