0

I would like to update the selectizeInput using the selected values s_l based on the condition input.c_l_check=='y'

ShinyUi <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput('s_l', 'D to show:', levels(data$D), selected = levels(data$D)),

      radioButtons("c_l_check", "D to colour:", list("Yes"='y', "No"='n'), selected = 'n'),

      conditionalPanel( condition = "input.c_l_check=='y'",
        selectizeInput( inputId = "c_l", label = "D to color:", multiple  = T, choices = NULL))
      ...

  ))

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

  # Updating selectize input
  updateSelectizeInput(session, 'c_l', choices = 'input$s_l', server = TRUE) 

  ...
}

# Run the application 
shinyApp(ui = ShinyUi, server = ShinyServer)

However, it is updating using the input$s_l rather than its values.

Prradep
  • 5,506
  • 5
  • 43
  • 84

1 Answers1

1

It should be: updateSelectizeInput(session, 'c_l', choices = input$s_l, server = TRUE)

that is input$s_l should be without quotes.

EDIT:

Here is a working example:

data <- data.frame(D = iris$Species)

ShinyUi <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput('s_l', 'D to show:', levels(data$D), selected = levels(data$D)),

      radioButtons("c_l_check", "D to colour:", list("Yes"='y', "No"='n'), selected = 'n'),

      conditionalPanel( condition = "input.c_l_check=='y'",
                        selectizeInput( inputId = "c_l", label = "D to color:", multiple  = T, choices = NULL))


    ),
    mainPanel()
    ))

  ShinyServer <- function(input, output, session) {
    observe({
      # Updating selectize input
      updateSelectizeInput(session, 'c_l', choices = input$s_l, server = TRUE) 
    })


  }

  # Run the application 
  shinyApp(ui = ShinyUi, server = ShinyServer)
SBista
  • 7,479
  • 1
  • 27
  • 58
  • It is giving the value `s_l` not the `levels(data$D)`. If you already have a working example of it, can you please point to me. – Prradep Jun 05 '17 at 14:20
  • `observe` is the key to the solution. It worked, thanks! On the sidelines, can you please have a look at [this](https://stackoverflow.com/q/44324783/4836511) if it is answerable? – Prradep Jun 05 '17 at 14:51