【问题标题】:How to specify different radiobutton with different styles in shiny?如何在闪亮中指定具有不同样式的不同单选按钮?
【发布时间】:2023-03-19 03:23:01
【问题描述】:

我正在尝试开发一个包含多个面板的闪亮应用程序,每个面板都有一些单选按钮。我目前的问题是:当我尝试像下面的代码一样指定某个单选按钮的样式时,CSS 会自动应用于整个应用程序中的其他单选按钮。

fluidRow(column(12, align='center',h4(tags$style(HTML(".radio-inline {margin-right: 200px;}"))), 
radioButtons("MPL1",label="",choiceNames=c("(60, 0; 12, 1)","(56, 0; 48, 1)"),
choiceValues=c(0,1),selected= character(0),inline=T))),

有些人提到我需要使用#inputID,但这个技巧不适用于我的情况。将“.radio-inline”替换为“#MPL1”后,代码无效(应用可以打开,但按钮为默认样式)。

fluidRow(column(12, align='center',h4(tags$style(HTML("#MPL1 {margin-right: 200px;}"))), 
radioButtons("MPL1",label="",choiceNames=c("(60, 0; 12, 1)","(56, 0; 48, 1)"),
choiceValues=c(0,1),selected= character(0),inline=T))),

你能告诉我我哪里出错了吗?欢迎任何帮助。非常感谢!

【问题讨论】:

    标签: r shiny radio-button elementstyle


    【解决方案1】:

    您可以在div() 中指定class。然后这会影响使用该class 定义的所有项目。

    试试这个

    ui <- fluidPage(
      fluidRow(column(12, align='center', 
                      div(class="MPL", radioButtons("MPL1",label="",choiceNames=c("(60, 0; 12, 1)","(56, 0; 48, 1)"),
                                   choiceValues=c(0,1),selected= character(0),inline=T)))),
      fluidRow(column(12, align='center', h4(tags$style(HTML(".radio-inline {margin-right: 100px;}"))),
                      radioButtons("MPL2",label="",choiceNames=c("(61, 0; 12, 1)","(55, 0; 48, 1)"),
                                   choiceValues=c(0,1),selected= character(0),inline=T))),
      fluidRow(column(12, align='center',h4(tags$style(HTML(".MPL .radio-inline {margin-right: 300px;}"))),
                      div(class="MPL", radioButtons("MPL3",label="",choiceNames=c("(62, 0; 12, 1)","(54, 0; 48, 1)"),
                                   choiceValues=c(0,1),selected= character(0),inline=T)) ) ),
      fluidRow(column(12, align='center',
                      radioButtons("MPL4",label="",choiceNames=c("(63, 0; 12, 1)","(53, 0; 48, 1)"),
                                   choiceValues=c(0,1),selected= character(0),inline=T)))
    )
    server <- function(input, output, session) {}
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 2021-09-03
      • 1970-01-01
      • 2018-07-23
      • 2021-01-26
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多