使R shine中的selectInput的第一个元素显示为粗体

时间:2018-01-29 11:15:19

标签: css r shiny shinydashboard

我希望制作第一个元素" 1"的SELECTInput粗体颜色。请帮忙。

ui <- fluidPage(
selectInput(
"select",
label = h3("Select box"),
choices = c(1,2,3,4)
))
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)

snapshot

4 个答案:

答案 0 :(得分:2)

查看shinyWidgets包含有pickerInput

的很多很酷功能的包
rm(list = ls())
library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  pickerInput(inputId = "Id069", 
              label = "Style individual options with HTML", 
              choices = c("steelblue 150%", 
                          "right align + red", "bold", 
                          "background color"), choicesOpt = list(style = c("color: steelblue; font-size: 150%;", 
                                                                           "color: firebrick; text-align: right;", 
                                                                           "font-weight: bold;", "background: forestgreen; color: white;")))

  )
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)

答案 1 :(得分:1)

您可以在CSS中使用伪元素

<style>
    option:first-child{
    font-weight:bold;
    color:#ff0000;
    }
</style>

答案 2 :(得分:1)

您可以在闪亮的应用中添加 @Nitin Shinde 建议的样式,如下所示:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M7:run (default-cli) on project demo: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 1; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'mappingMongoConverter' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mappingMongoConverter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Invocation of init method failed;
nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/jvm/internal/impl/load/kotlin/reflect/ReflectKotlinClass:
kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectKotlinClass

输出将是这样的:

enter image description here

答案 3 :(得分:0)

您可以使用下面的内容,并在div中使用class =“test”将每个selectInput嵌套到您希望第一个项目为粗体的每个中。

ui <- fluidPage(

  tags$head(tags$style(".test .option:first-child{
                       font-weight:bold;
                       //color:#ff0000;
                       }")),
  div(class = "test",selectInput(
    "select",
    label = h3("Select box"),
    choices = c(1,2,3,4)
  )),
  selectInput(
    "select2",
    label = h3("Select box"),
    choices = c(1,2,3,4)
  )

  )
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)

您可以将div的类设置为您喜欢的任何内容,只需确保相应地更改CSS的.test部分。

更新“// color:#ff0000;” “color:#ff0000;”将颜色更改为红色,只需将十六进制代码更新为您想要使用的颜色。