2015-08-28 109 views
1

我想知道如何使用css(tag $ style())更改“radioButton”和“checkboxInput”窗口小部件的样式。更改窗口小部件的样式

任何帮助表示赞赏! 谢谢!

library(shiny) 

ui <- shinyUI(fluidPage(
    h3("Hi! I would like to know how to change the style of these widgets with css (tag$style)"), 
    h3("I can change the style of sliders, unfortunately I cannot figure out how to do this with 'radioButtons' 
    and 'checkboxInput'. I usually inspect HTML-element in my browser and look for the css style, in this case this strategy does not work."), 
    br(), 
    br(), 
    radioButtons(inputId = "ex_radio", label = "How to change my style?", 
       choices = c("I want to be red when checked", "I want to be green")), 
    br(), 
    br(), 

    checkboxInput(inputId = "ex_checkbox", label = "I'd like to look bit different as well", 
       value = TRUE), 

    br(), 
    br(), 
    h3("Any help is appreciated :) Thank you!") 
)) 


server <- shinyServer(function(input, output) { }) 

shinyApp(ui, server) 

回答

4

您要更改的文本位于<span>。您可以通过使用element+element CSS选择器中选择无线输入后的第一个span

tags$style("input[type='radio']:checked+span{ 
      color: red; 
      } 
input[type='radio']+span{ 
    color: green; 
}") 

详情请参阅here。由type=checkbox更换type='radio'

#ex_radio input[type='radio']:checked+span{ 
      color: red; 
      } 

对于复选框,你可以做同样的事情:如果你有一个以上的单选按钮的元素,你可以明确这个CSS应用到其中的一个使用#id选择,为前。

+0

感谢您提供非常快速的答案! :) 有没有办法改变按钮的蓝色? (不是标签) –

+0

要更改颜色,您可以查看[this post](http://stackoverflow.com/questions/4253920/how-do-i-change-the-color-of-radio-buttons),不确定它可以很容易地用CSS来完成。 – NicE

相关问题