闪亮 - 如何为选定的单选按钮标签设置样式?

3

我发现一个相似的问题,但没有解决在Shiny中原生处理这些单选按钮时所遇到的问题;即,没有使用HTML。

我有这行代码:

column(6, h1(radioButtons(inputId="gender", "Gender", choices = list("combined" = "combined", "male only" = "male", "female only" = "female"), inline=TRUE)))

以下是需要翻译的内容:

页面如下所示:

enter image description here

我想把标签(例如,“合并”,“仅男性”,“仅女性”)加粗显示。

我试着设置一个类,如下所示:class="radioSelect"

请注意,以上内容中已经包含了HTML标签,翻译时应予以保留。

column(6, h1(radioButtons(inputId="gender", "Gender", choices = list(class="radioSelect", combined" = "combined", "male only" = "male", "female only" = "female"), inline=TRUE)))

最终结果令人欣喜和意料之外,如下图所示:

enter image description here

请问有没有关于如何在Shiny中的单选按钮上应用类的建议?感谢您的关注。

3个回答

4

我最终修改了R代码,加入了一个名为radioSelect的类:

column(6, h1(class="radioSelect", radioButtons(inputId="gender", "Gender", choices = list(...

然后在CSS文件中,我使用以下方式访问标签:

.radioSelect label.radio { ...

这个方法有效是因为所有标签都有'class'属性且值为'radio'。因此,我现在可以控制这些标签。


2

我曾遇到类似问题,发现以下方法可以改变整个单选按钮的样式:

column(6, h1(radioButtons(inputId="gender", "Gender", choices = list(...)), style = "font-weight:bold;")

1
<div class="thisForm">
column(6, h1(radioButtons(inputId="gender", "Gender", choices = list(class="radioSelect", combined" = "combined", "male only" = "male", "female only" = "female"), inline=TRUE)))
</div>

CSS
.thisForm{
font-weight: bold;
}

至少在这里的文档中是这样完成的: http://shiny.rstudio.com/reference/shiny/latest/radioButtons.html

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接