0
votes

I am using checkboxGroupInput() from the Shiny/ShinyDashboard-package to let users (de-)select elements of a plot (MorrisJS). The selection is passed from a named list as the choices-Argument to a function updating a data.frame (adding and removing elements).

However, input$NameOfTheCheckboxGroup returns only a vector with the selected choices, but not the label/name of the member in the list it takes as input. This means I can only name elements with the value that I assigned to a choice.

Is there any way to improve that, so input$NameOfTheCheckboxGroup also returns the label/name? So far I have tried replacing the "y"-Argument in the plot to return the label of the list member, but this cannot work, as the plot cannot find the data columns.

Replaced this:

y = colnames(de_solar)[2:NCOL(de_solar)]

With:

y = names(list1[match(colnames(df)[2:NCOL(df)],list1)])

Renaming the list members is unfortunately not an option.

[UI]

checkboxGroupInput("check_de_solar", label = h3("Label"), 
                                   choices = list("Option1" = 2097,
                                                  "Option2" = 409,
                                                  "Option3" = 410,
                                                  "Option4" = 411,
                                                  "Option5" = 412,
                                                  "Option6" = 2106,
                                                  "Option7" = 2107,
                                                  "Option8" = 2108,
                                                  "Option9" = 2109, 
                                                  "Option10" = 731),
                                                  selected = 2097)

[SERVER]

  output$de_solar <- renderChart2({

    de_solar <<- checkbox_call(df_data,"de_solar",input$check_de_solar)
    grph2 <- mPlot(x = "Date", y = colnames(de_solar)[2:NCOL(de_solar)], data = de_solar, type = "Line")

  })

To further illustrate, the current data.frame de_solar and list choices look like this:

 de_solar = data.frame(replicate(10,sample(0:50,10,rep=TRUE)))
choices = list("Option1" = 2097,
             "Option2" = 409,
             "Option3" = 410,
             "Option4" = 411,
             "Option5" = 412,
             "Option6" = 2106,
             "Option7" = 2107,
             "Option8" = 2108,
             "Option9" = 2109, 
             "Option10" = 731)
 names(de_solar) <- choices

This gives me this output: What I have

But I want the same input to be: enter image description here

Thank you for your help.

1
I apologize for not having selected your answer before. Your solution solved the problem.lammy

1 Answers

1
votes

Is there any way to improve that, so input$NameOfTheCheckboxGroup also returns the label/name?

Not really. Label information is not a part of the generated request so unless you want to implement a custom client-side logic it is not an option. As long as values are unique it shouldn't be a problem though. You can simply match values and extract names for example like this:

names(choices[choices %in% input$check_de_solar])

where choices is a list of character values:

list("Option1" = "2097", "Option2" = "409", ..., "Option10" = "731")