Debian Codegraph @

man/conditionalPanel.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/bootstrap.R
3 \name{conditionalPanel}
4 \alias{conditionalPanel}
5 \title{Conditional Panel}
6 \usage{
7 conditionalPanel(condition, ..., ns = NS(NULL))
8 }
9 \arguments{
10 \item{condition}{A JavaScript expression that will be evaluated repeatedly to
11 determine whether the panel should be displayed.}
12
13 \item{...}{Elements to include in the panel.}
14
15 \item{ns}{The \code{\link[=NS]{namespace()}} object of the current module, if
16 any.}
17 }
18 \description{
19 Creates a panel that is visible or not, depending on the value of a
20 JavaScript expression. The JS expression is evaluated once at startup and
21 whenever Shiny detects a relevant change in input/output.
22 }
23 \details{
24 In the JS expression, you can refer to \code{input} and \code{output}
25 JavaScript objects that contain the current values of input and output. For
26 example, if you have an input with an id of \code{foo}, then you can use
27 \code{input.foo} to read its value. (Be sure not to modify the input/output
28 objects, as this may cause unpredictable behavior.)
29 }
30 \note{
31 You are not recommended to use special JavaScript characters such as a
32 period \code{.} in the input id's, but if you do use them anyway, for
33 example, \code{inputId = "foo.bar"}, you will have to use
34 \code{input["foo.bar"]} instead of \code{input.foo.bar} to read the input
35 value.
36 }
37 \examples{
38 ## Only run this example in interactive R sessions
39 if (interactive()) {
40 ui <- fluidPage(
41 sidebarPanel(
42 selectInput("plotType", "Plot Type",
43 c(Scatter = "scatter", Histogram = "hist")
44 ),
45 # Only show this panel if the plot type is a histogram
46 conditionalPanel(
47 condition = "input.plotType == 'hist'",
48 selectInput(
49 "breaks", "Breaks",
50 c("Sturges", "Scott", "Freedman-Diaconis", "[Custom]" = "custom")
51 ),
52 # Only show this panel if Custom is selected
53 conditionalPanel(
54 condition = "input.breaks == 'custom'",
55 sliderInput("breakCount", "Break Count", min = 1, max = 50, value = 10)
56 )
57 )
58 ),
59 mainPanel(
60 plotOutput("plot")
61 )
62 )
63
64 server <- function(input, output) {
65 x <- rnorm(100)
66 y <- rnorm(100)
67
68 output$plot <- renderPlot({
69 if (input$plotType == "scatter") {
70 plot(x, y)
71 } else {
72 breaks <- input$breaks
73 if (breaks == "custom") {
74 breaks <- input$breakCount
75 }
76
77 hist(x, breaks = breaks)
78 }
79 })
80 }
81
82 shinyApp(ui, server)
83 }
84 }