我看过几篇有关更改实际下拉项的颜色以供选择的文章,许多文章似乎都需要冗长的CSS调用和文件。如果我们想要的唯一格式更改就是更改某些下拉标题或部分下拉标题的字体颜色,例如Select Breakfast
或仅更改Breakfast
,例如紫色?
server <- function(input, output) {
output$distPlot <- renderPlot({
hist(rnorm(input$user_choice1))
})
}
ui <- fluidPage(
column( width = 5,
selectInput("user_choice1",
"Select Breakfast",
choices = c("good", "better", "amazing"), selected = "amazing") ) ,
column( width = 5,
selectInput("user_choice2",
"Select Dinner",
choices = c("bad", "mediocre", "ok"), selected = "ok") ,
mainPanel(plotOutput("distPlot"))))
shinyApp(ui = ui, server = server)
答案 0 :(得分:1)
这件衣服怎么样?您可以看到我使用最少的CSS和ID来指定要更改的列:
library(shinydashboard)
library(shiny)
library(tableHTML)
server <- function(input, output) {
output$distPlot <- renderPlot({
hist(rnorm(input$user_choice1))
})
}
ui <- fluidPage(
column(id = "columns", width = 5,
selectInput("user_choice1",
"Select Breakfast",
choices = c("good", "better", "amazing"), selected = "amazing") ) ,
column( width = 5,
selectInput("user_choice2",
"Select Dinner",
choices = c("bad", "mediocre", "ok"), selected = "ok") ,
mainPanel(plotOutput("distPlot"))),
tags$style(make_css(list('#columns',
c('font-size', 'font-family', 'color'),
c('15px', 'calibri light', 'red'))))
)
shinyApp(ui = ui, server = server)
答案 1 :(得分:1)
如果您需要对标签中的单个单词进行更改,那么最简单的方法就是传递一个原始的html字符串来完成您想要的操作。请注意,它仍然会继承label
library(shiny)
server <- function(input, output) {
}
ui <- fluidPage(
column( width = 5,
selectInput("user_choice1",
shiny::HTML("<p>Select <span style='color: purple'>Breakfast</span></p>"),
choices = c("good", "better", "amazing"), selected = "amazing") ) ,
column( width = 5,
selectInput("user_choice2",
"Select Dinner",
choices = c("bad", "mediocre", "ok"), selected = "ok") ,
mainPanel(plotOutput("distPlot"))))
shinyApp(ui = ui, server = server)