Skip to content

update_material_dropdown fails to update choices and values correctly with multiple = TRUE #125

@jameswcraig

Description

@jameswcraig

Hi,

I have 2 dropdowns in below example - attempting to update choices in dropdown 2 with values selected in dropdown 1, while also retaining previously selected choices in dropdown 2. You can reproduce error by: first selecting "a" in dropdown 2, then, selecting "a", "b", "c" in dropdown 1, then attempting to change selections in dropdown 2 with newly available choices from dropdown1 will disable further selections..

Note: Also tried using observereEvent(input$dropddown1{...}) for the update_material_dropdown observer but the issue where user cannot further select choices in dropdown2 still appears (although delayed).

library(shinymaterial)
library(shinyjs)


ui <- material_page(
  useShinyjs(),
  material_dropdown("dropdown1", label = "dropdown1", choices = c("a","b","c","d"), multiple = TRUE),
  material_dropdown("dropdown2", label = "dropdown2", choices = c("a","b","c","d"), multiple =TRUE)
)

server <- function(input, output, session){
 
  
  reactives <- reactiveValues( 
    val = list()
  )
  
  observe({
    reactives$val$choices <- input$dropdown1
    reactives$val$values <- input$dropdown2
  }, priority = 1)
  
  observe({
    update_material_dropdown(session, input_id = "dropdown2", choices = reactives$val$choices, value = reactives$val$values )
  })
}

shinyApp(ui, server)

Thanks again for your work on this package, this functionality seems to be quite important that it works correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions