Shiny R Selectize Input小部件的大小以输入为目标



我的Shiny应用程序中有多个SelectionInput。它们中的大多数不应该充满变量/元素,但其中一个是的。问题是,框中的变量/元素越多,这个变量/元素就越大,显示效果也不好。我已经找到了处理输入小部件的高度、字体、宽度等的解决方案:

library(shiny)
ui <- fluidPage(
fluidRow(
selectInput("speed", label=NULL, choices = list("1" = 1, "2" = 2), selected = 1),
tags$head(tags$style(HTML(".selectize-input {height: 100px; width: 500px; font-size: 100px;}")))
)
)
server <- function(input, output){}
shinyApp(ui, server)

这是有效的。但这个解决方案会影响我应用程序中的所有selectizeInput,我只对一个selectizeInput感兴趣。有办法做到这一点吗?

您可以使用一些高级CSS来选择.selectize-input框。因此,在selectInput结构中,具有实际id的元素被分配给select标记,而您想要的框是select标记之后的下一个标记的第一个子元素。我们可以使用+来选择以下标记,并使用>来选择包含以下标记的.selectize-input类的第一个子级。

library(shiny)
ui <- fluidPage(
tags$head(tags$style(HTML("#speed + div > .selectize-input {height: 100px; width: 500px; font-size: 100px;}"))),
fluidRow(
selectInput("speed", label=NULL, choices = list("1" = 1, "2" = 2), selected = 1),
selectInput("speed2", label=NULL, choices = list("1" = 1, "2" = 2), selected = 1)
)
)
server <- function(input, output){}
shinyApp(ui, server)

#ID + div > .selectize-input是您想要申请的。

试着运行我的示例,我创建了两个selectInput,只有第一个具有CSS样式。

最新更新