使用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}"

                 )




    )

  })



}


千巷猫影
浏览 137回答 2
2回答

慕村225694

如果你把它应该工作selectize = FALSE。默认情况下,selectInput有selectize = TRUE它使用selectize.js。因此,如果您按原样运行代码,那么您应该会看到您的选择显示为&nbsp;display: none所以你output$menu会像&nbsp; output$menu<-renderUI({&nbsp; &nbsp; sidebarPanel(width = 2,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;selectInput("sel","",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;choices = c("Home","About","Sector A","Sector B","Sector C"),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;selected = "Home", selectize = FALSE),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tags$style(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"select#sel {background: #FFA500}"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)&nbsp; &nbsp; )&nbsp; })

拉丁的传说

根据您编辑的问题,您可能会在周围使用 div 容器 selectInputdiv(&nbsp;selectInput("sel","",&nbsp; &nbsp;choices = c("Home","About","Sector A","Sector B","Sector C"),&nbsp; &nbsp;selected = "Home"),&nbsp;style = "background: #FFA500")或者,如果您想设置整个侧边栏面板的样式,请设置样式 form.wellsidebarPanel(&nbsp; width = 2,&nbsp; selectInput(&nbsp; &nbsp; "sel","",&nbsp; &nbsp; choices = c("Home","About","Sector A","Sector B","Sector C"),&nbsp; &nbsp; selected = "Home"),&nbsp; tags$style(&nbsp; &nbsp; "form.well {background: #FFA500}"&nbsp; ))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript