rshinypickerinput

Why does adding inputId to my pickerInput segment of my shiny app break my code?


#UI BEGINS
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      pickerInput("chosenplans", "Select State:",
                  #inputId = "stateList",
                  choices = as.character(unique(state_plan_data_filtered$state)),
                  options = list(
                    `actions-box` = TRUE,
                    `live-search` = TRUE),
                  multiple = FALSE,
                  selected = "Alabama"),
      ),
  mainPanel()
  ),
)

Whenever I uncomment my inputId, I can't run my Shiny app, and it gives me this error:

Error in choicesOpt$style : $ operator is invalid for atomic vectors

However, inputId is theoretically an argument for pickerInput. Why can't I explicitly name it?


Solution

  • Note that the arguments that pickerInput expects are

    args(pickerInput)
    function (inputId, label = NULL, choices, selected = NULL, multiple = FALSE, 
        options = list(), choicesOpt = NULL, width = NULL, inline = FALSE) 
    

    The value of "chosenplans" that you are passing to the function is going to the inputId= parameter by default since that's the first unnamed parameter that it woudl match. However when you add inputId = "stateList" you seem to be trying to add a second ID, but this now means the value of "chosenplans" will be passed to the first parameter that you haven't already specified which means that will so to the label= parameter and "Select State:" gets passed to the chociesOpt= parameter. THis is not a valid value for choicesOpt which is what generates the error.

    The the problem is you labeling some parameters and not others and specifying an inputId= two different ways which shuffles the parameters around in an unexpected way.