首页 > 解决方案 > 使用javascript更改R闪亮中selectinput的背景颜色

问题描述

我有一个简单的闪亮应用程序,我想使用 javascript 将我的 selectInput() 的背景颜色从白色更改为橙​​色。可能吗?我应该把callback论据放在哪里?

#ui.r
library(shiny)
ui <- fluidPage(


  theme=shinytheme("slate") ,
  # App title ----
  titlePanel(uiOutput("title")),

  #This hides the temporary warning messages while the plots are being created
  tags$style(type="text/css",
             ".shiny-output-error { visibility: hidden; }",
             ".shiny-output-error:before { visibility: hidden; }"
  ),


  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    uiOutput("menu"),



    # Main panel for displaying outputs ----
    mainPanel(

    )
  )
)
#server.r
server = function(input, output) {


  output$menu<-renderUI({

    sidebarPanel(width = 2,
                 selectInput("sel","",
                             choices = c("Home","About","Sector A","Sector B","Sector C"),
                             selected = "Home"),
                 tags$style(
                   "select#sel {background: #FFA500}"
                 )



    )
  })


}

标签: javascriptrshiny

解决方案


根据您编辑的问题,您可能会使用 div 容器selectInput

div(
 selectInput("sel","",
   choices = c("Home","About","Sector A","Sector B","Sector C"),
   selected = "Home"),
 style = "background: #FFA500"
)

或者,如果您想为整个侧边栏面板设置样式,请设置样式form.well

sidebarPanel(
  width = 2,
  selectInput(
    "sel","",
    choices = c("Home","About","Sector A","Sector B","Sector C"),
    selected = "Home"),
  tags$style(
    "form.well {background: #FFA500}"
  )
)

推荐阅读