【问题标题】:R shiny radiogroup Button change colorR闪亮的radiogroup按钮更改颜色
【发布时间】:2021-03-04 18:52:54
【问题描述】:

我正在使用库 shinythemes https://rstudio.github.io/shinythemes/ 但我想更改单选按钮的颜色。如何更改颜色?

               radioGroupButtons(
                 status = "primary ",
                 inputId = "indicadores_radiogroup",
                 choices = c("Casos" = "Confirmados", "Muertes"= "Muertes"),
                 
               ),

谢谢

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    对于你自己的特定颜色,你可以尝试以下:

    ui = fluidPage(
        radioGroupButtons(
          #status = "primary ",  ##  you can change status value to change to select few colors
          inputId = "indicadores_radiogroup",
          checkIcon = list(yes = icon("check")),
          choiceValues = c("Confirmados", "Muertes"), 
          choiceNames = c("Casos", "Muertes"),
          justified = TRUE, width = "300px"
        ),
        tags$script("$(\"input:radio[name='indicadores_radiogroup'][value='Confirmados']\").parent().css('background-color', '#FF4500');"),
        tags$script("$(\"input:radio[name='indicadores_radiogroup'][value='Muertes']\").parent().css('background-color', '#7EF373');"),
    
      )
      server = function(...) {}
    
      shinyApp(ui, server)
    

    【讨论】:

      【解决方案2】:

      您似乎正在使用shinyWidgets 包。您可以将status = "danger" 设置为红色,或将status = "success" 设置为绿色。检查http://shinyapps.dreamrs.fr/shinyWidgets/中的“单选按钮”面板

      radioGroupButtons(
         inputId = "Id064",
         label = "Label",
         choices = c("A", 
          "B", "C", "D"),
         status = "danger"
      )
      

      status 参数为您的按钮添加一个类。该示例为您的按钮提供btn-danger 类。检查关联的 css。

      .btn-danger {
          color: #fff;
          background-color: #d9534f;
          border-color: #d43f3a;
      }
      

      您可以使用任意字符串来添加自定义类,例如:使用status = 'myClass',按钮将具有btn-myClass 类。然后你需要指定 css。

      .btn-myClass {
          background-color: #ff4500;
      }
      

      【讨论】:

      • 是的,我正在使用闪亮的小部件,但是如果我想要一个特定的颜色“#FF4500”,例如这样
      • 检查编辑。您可以使用status 为您的按钮生成自定义类
      猜你喜欢
      • 2016-02-10
      • 2021-07-12
      • 1970-01-01
      • 2020-06-22
      • 2018-11-20
      • 2018-04-17
      • 2021-08-29
      • 2016-06-28
      • 1970-01-01
      相关资源
      最近更新 更多