disable select input conditionally

1,635 views
Skip to first unread message

Jie Song

unread,
Nov 7, 2014, 4:54:40 AM11/7/14
to shiny-...@googlegroups.com
 can anybody tells me how to disable some widgets conditionally?
For example, after the user import the data and choose some parameters, I want to disable those select input box that the user can't change it later on unless he/she starts it all over again.

Thanks for the help in advance.


Huidong TIAN

unread,
Nov 7, 2014, 5:02:41 AM11/7/14
to shiny-...@googlegroups.com
Do you mean the users can only change the input once? 

Jie Song

unread,
Nov 7, 2014, 6:46:15 AM11/7/14
to shiny-...@googlegroups.com
 Yes, for some input, I want to control them and let them only change once.
As soon as they decide and click some kind of button, those input selects are diabled.
Do you have a way to do that?

在 2014年11月7日星期五UTC+1上午11时02分41秒,Huidong TIAN写道:

Huidong TIAN

unread,
Nov 7, 2014, 7:11:48 AM11/7/14
to shiny-...@googlegroups.com
I don't know how to block the input, but you can hide them, so the user can't find them, then they can't change them. 

You create a reactiveValue, let it's initial value equal to 0, them and put it in your input widget, like 

p <- reactiveValues()
p$count <- 0

output$uiYear <- renderUI({
  if (p$count < 3) {

  checkboxInput(inputId = "year",  value   = FALSE)
 }
})

output$Fig <- renderPlot({
  input$year
  p$count <- p$count+1

  plot(rnorm(10))
})

PS. I never tried above code.

Joe Cheng

unread,
Nov 7, 2014, 1:27:57 PM11/7/14
to Huidong TIAN, shiny-...@googlegroups.com
Disabling isn't currently possible through our R APIs. If you're familiar with JavaScript you could use sendCustomMessage to do this using JS, see the section on "Sending data from server to client":

--
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/840fd9fe-4f6d-4f54-a369-321e09bf28af%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dean Attali

unread,
May 23, 2015, 8:18:30 PM5/23/15
to shiny-...@googlegroups.com
Hi Jie, you can use my package shinyjs for that

Example for what you want:
library(shiny)
library(shinyjs)
runApp(shinyApp(
  ui = fluidPage(
    useShinyjs(),
    selectInput("test", "Select once", letters),
    actionButton("submit", "Choose")
  ),
  server = function(input, output, session) {
    observeEvent(input$submit, {
      disable("test")
    })
  }
))
Reply all
Reply to author
Forward
0 new messages