Hiding or showing shiny elements without pressing submit

1,417 views
Skip to first unread message

Aaghaz

unread,
Nov 27, 2015, 1:21:27 AM11/27/15
to Shiny - Web Framework for R
have a shiny app where i want to hide or show some elements based on user input. This i tried to do by using conditionalPanel in shiny. However, it works only after pressing the submit button. I want to hide or show the textInput element without pressing the submit button. Below is an example what I tried.

UI.R:
library(shiny)
shinyUI(fluidPage(
  titlePanel("submitButton example"),
  fluidRow(
    column(3, wellPanel(
      sliderInput("n", "N:", min = 10, max = 1000, value = 200,
                  step = 10),
      checkboxInput("checkbox", label = "Message", value = FALSE),
      conditionalPanel(
        condition = "input.checkbox == true",
        textInput("text", "Text:", "text here")),

      submitButton("Submit")
    )),
    column(6,
           plotOutput("plot1", width = 400, height = 300),
           verbatimTextOutput("text")
    )
  )
))

Server.R:
shinyServer(function(input, output) {
  output$plot1 <- renderPlot({
    hist(rnorm(input$n))
  })

  output$text <- renderText({
    paste("Input text is:", input$text)
  })
})

I want to show the textInput as soon as user checks the checkbox and hide it on uncheck without any dependency on submit button.

Joe Cheng

unread,
Nov 28, 2015, 1:52:59 PM11/28/15
to Aaghaz, Shiny - Web Framework for R
submitButton is very limited in applicability due to issues like this. However, action buttons are a much more powerful/flexible mechanism for achieving the same results:

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/e0db2e6c-6a3d-4b5b-848e-7384012c4bda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages