I'm using radioGroupButtons
with different colors based on this code: https://github.com/dreamRs/shinyWidgets/issues/41#
Now I want to be able to update the choices, but the colors disappears when i'm updating with updateRadioGroupButtons
. If i'm only updating the selected value everything is fine, but if I update choiceValues
and choiceNames
the colors disappears.
Reproducible code:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
radioGroupButtons(
inputId = "sent",
label = "Sentiment",
choiceValues = -2:1,
checkIcon = list(yes = icon("check")),
choiceNames = paste0(-2:1),
justified = TRUE, width = "300px"
),
tags$script("$(\"input:radio[name='sent'][value='-2']\").parent().css('background-color', '#DE6B63');"),
tags$script("$(\"input:radio[name='sent'][value='-1']\").parent().css('background-color', '#EDB6B2');"),
tags$script("$(\"input:radio[name='sent'][value='0']\").parent().css('background-color', '#E7E7E7');"),
tags$script("$(\"input:radio[name='sent'][value='1']\").parent().css('background-color', '#B2EDB5');"),
tags$script("$(\"input:radio[name='sent'][value='2']\").parent().css('background-color', '#7EF373');"),
verbatimTextOutput(outputId = "res"),
actionButton(inputId = "update", label = "Update")
)
server <- function(input, output, session) {
output$res <- renderPrint(input$sent)
observeEvent(input$update, {
updateRadioGroupButtons(session = session, inputId = "sent", choiceValues = -2:2, choiceNames = paste0(-2:2))
}, ignoreInit = TRUE)
}
shinyApp(ui, server)