我正在使用radioGroupButtons
基于此代码的不同颜色:https ://github.com/dreamRs/shinyWidgets/issues/41#
现在我希望能够更新选择,但是当我使用updateRadioGroupButtons
. 如果我只更新所选值一切都很好,但如果我更新choiceValues
并且choiceNames
颜色消失。
可重现的代码:
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)