RadioButtons and checkBoxGroup do not work in modules when they are updated

106 views
Skip to first unread message

Simon Müller

unread,
Mar 31, 2016, 11:11:53 AM3/31/16
to Shiny - Web Framework for R

RadioButtons and checkBoxGroup do not work in modules when they are updated, selectInput and textInput work as intended. I build following example app to show the issue:

library(shiny)

testInput <- function(id) {
 
ns <- NS(id)
  tagList
(
    selectInput
(inputId = ns("input1"), label = "Updater", choices = c("Value A", "Value B")),
    hr
(),
    radioButtons
(inputId = ns("input2"), label = "Radio Buttons", choices = c("Value AA", "Value AB")),
    selectInput
(inputId = ns("input3"), label = "Select Input", choices = c("Value AA", "Value AB")),
    textInput
(inputId = ns("input4"), label = "Text Input", value = "Value AA"),
    checkboxGroupInput
(inputId = ns("input5"), label = "Checkbox Group", choices = c("Value AA", "Value AB")),
    radioButtons
(inputId = ns("input6"), label = "Radio Buttons (No Update)", choices = c("Value AA", "Value AB")),
    checkboxGroupInput
(inputId = ns("input7"), label = "Checkbox Group (No Update)", choices = c("Value AA", "Value AB"))
 
)
}

testModule <- function(input, output, session) {

  observeEvent
(input$input1, {
   
ns <- session$ns
   
if (input$input1 == "Value A") {
     
values <- c("Value AA", "Value AB")
   
} else {
     
values <- c("Value BA", "Value BB")
   
}
    updateRadioButtons
(session = session, inputId = "input2", label = "Radio Buttons", choices = values)
    updateSelectInput
(session = session, inputId = "input3", label = "Select Input", choices = values)
    updateTextInput
(session = session, inputId = "input4", label = "Text Input", value = values[1])
    updateCheckboxGroupInput
(session = session, inputId = "input5", label = "Checkbox Group", choices = values)
 
})

 
dataframe <- reactive({
   
data.frame(radioButton = input$input2,
               
radioButton_no_update = input$input6,
               
SelectInput=input$input3,
               
TextInput=input$input4,
               
Checkboxes=paste0(input$input5, collapse = ", "),
               
checkBox_no_update = paste0(input$input7, collapse = ", "),
               
value = rnorm(1))
 
})

 
return(dataframe)
}

ui <- fluidPage(
  sidebarLayout
(
    sidebarPanel
(
      testInput
("test")
   
),
    mainPanel
(
      dataTableOutput
("table")
   
)
 
)
)

server <- function(input, output, session) {
 
exampledata <- callModule(testModule, "test")

 
output$table <- renderDataTable({
    exampledata
()
 
})
}

shinyApp
(ui, server)

Thx for looking at the code. The second column name radioButton_no_update should be named checkBox_no_update, but this is just a typo. Yes, it is updated, but it do not trigger the reactive function and if the reactive function is triggered, you get the not updated value. 
Element with id input1 will update elements with ids input2, input3, input4, and input5, but not input6 and input7. Elements with ids input2, ..., input7 are in the data.frame such that the reactive function should be triggered if one of this elements is changed.

MySchizo Buddy

unread,
Apr 4, 2016, 9:36:52 AM4/4/16
to Shiny - Web Framework for R
 ok This looks like a namespace issue.
the id for the radio button initially is test-input2. test being the namespace
<input type="radio" name="test-input2" value="Value AA" checked="checked">

Once the the values are updated the id changes to input2 which breaks the binding.
<input type="radio" name="input2" value="Value BA" checked="checked">

For selectInput the id has the namespace in it and hence keeps working.

This looks like a bug.
Reply all
Reply to author
Forward
0 new messages