问题
ui <- fluidPage(
radioButtons("dist", "Distribution type:",
c("Normal" = "norm",
"Uniform" = "unif",
"Log-normal" = "lnorm",
"Exponential" = "exp")))
server <- function(input, output) {}
I would like the font colors of "Normal" and "Uniform" to be different than those of the other choices. Let's say the color of the first two choices should be red.
Anyone who can achieve that?
回答1:
Just look at the examples in ?radioButtons
. This will give you instructions on how to apply HTML
tags to choices.
To summarize, you will have to use the arguments choiceNames
and choiceValues
.
choiceNames
defines the ui of your radiobuttons. You can useHTML
tags (tags$strong
,tags$code
, ... andHTML("some html string")
)choiceValues
are the values that will be recieved by the server viainput$dist
.
Here is an example:
library(shiny)
shinyApp(
fluidPage(
radioButtons(
inputId = "dist",
label = "Distribution type:",
choiceNames = list(
HTML("<font color='red'>Normal</font>"),
tags$span(style = "color:red", "Uniform"),
"Log-normal", "Exponential"
),
choiceValues = c("norm", "unif", "lnorm", "exp")
)
),
server = function(...) {}
)
Also, take a look at shinyWidgets::shinyWidgetsGallery()
if you need inspiration for the styling of your radioButton
s.
来源:https://stackoverflow.com/questions/49616376/r-shiny-radiobuttons-how-to-change-the-colors-of-some-of-the-choices