0

I have 3 sets of radio buttons and I want to update/ reset them under certain conditions:

plotChoices <- c(
    "Line Graph" = "line",
    "Scatter Plot" = "scatter"
)

So if "line" is not selected all together at these 3 sets, then reset plot2's and plot2's:

observeEvent(input$plot1, {
    if (input$plot1 == 'line' &&
        (!is.null(input$plot2) && input$plot2 == 'line') &&
        (!is.null(input$plot3) && input$plot3 == 'line')
    ) return ()
    updateRadioButtons(
        session,
        "plot2",
        label = "Analyze Plot2 data:",
        choices = plotChoices,
        selected = character(0),
        inline = FALSE
    )
    updateRadioButtons(
        session,
        "plot3",
        label = "Analyze Plot3 data:",
        choices = plotChoices,
        selected = character(0),
        inline = FALSE
    )
    session$sendCustomMessage(type = "resetValue", message = "plot2")
})

But it does not work at all. It only reset plot2 but not plot3.

Any ideas? Is it a bug in Shiny?

Run
  • 54,938
  • 169
  • 450
  • 748
  • 1
    Are you using the right ID? It would be easier to help if you had a more complete [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that we could run and test to see what exactly is going on. – MrFlick Oct 26 '17 at 19:44
  • @MrFlick `Are you using the right ID?` Yes I am sure they all are correct. – Run Oct 26 '17 at 19:48
  • 1
    And you are only calling `session$sendCustomMessage(type = "resetValue", message = "plot2")` for "plot2"? – MrFlick Oct 26 '17 at 19:49
  • the problem seems to be coming from `selected = character(0),` – Run Oct 26 '17 at 19:49
  • `And you are only calling session$sendCustomMessage(type = "resetValue", message = "plot2") for "plot2"? ` it should be for plot3 as well. but it has no difference if I add that same line for plot3. – Run Oct 26 '17 at 19:50
  • If the problem is `character(0)` have you tried replacing it with `NULL`. This is what the default is set to anyway for `updateRadioButtons()` – Mike H. Oct 26 '17 at 21:35
  • @MikeH. it does not work by replacing it with `NULL`. the first item in the radio button list still selected. – Run Oct 26 '17 at 21:47
  • 2
    Radio buttons always need something selected. Try it with a `checkboxGroupInput` instead? – Mike H. Oct 26 '17 at 22:03
  • @MikeH. I have tried `checkboxGroupInput` before. any good examples? – Run Oct 26 '17 at 22:16
  • @MikeH. i found the example. thanks. i think Shiny is really a bad framework after a few years using it. it is extremely inflexible. – Run Oct 26 '17 at 22:19

0 Answers0