此问题采用的以下代码防止下拉菜单换行,并设置所有下拉菜单的宽度。
有没有一种方法可以自定义每个下拉菜单的宽度selectInput
?
library(shiny)
ui <- (fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("userInput","Select User", c(1,2,3),
selected=1),
selectInput("LongInput", "Long Strings", c("This is a long long string that is long.",
"This is a long long string that is longer."))
),
# allows for long texts to not be wrapped, and sets width of drop-down
tags$head(
tags$style(HTML('
.selectize-input {
white-space: nowrap;
}
.selectize-dropdown {
width: 660px !important;
}'
)
)
)
)
))
server <- function(input, output, session) {}
shinyApp(ui, server)
如果我了解你的权利,你需要
library(shiny)
ui <- (fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("userInput","Select User", c(1,2,3),
selected=1),
selectInput("LongInput", "Long Strings", c("This is a long long string that is long.",
"This is a long long string that is longer."))
),
# allows for long texts to not be wrapped, and sets width of drop-down
tags$head(
tags$style(HTML('
.selectize-input {
white-space: nowrap;
}
#LongInput + div>.selectize-dropdown{
width: 660px !important;
}
#userInput + div>.selectize-dropdown{
width: 300px !important;
}
'
)
)
)
)
))
server <- function(input, output, session) {}
shinyApp(ui, server)
将其设置为660pxLongInput
和300pxuserInput
您也可以将其做为dunamic,例如您使用输入名称和大小的df
df1=data.frame(name=c("LongInput","userInput"),px=c(600,300))
所以尝试
library(shiny)
ui <- (fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("userInput","Select User", c(1,2,3),
selected=1),
selectInput("LongInput", "Long Strings", c("This is a long long string that is long.",
"This is a long long string that is longer."))
),
uiOutput("din_css")
)
))
server <- function(input, output, session) {
df1=data.frame(name=c("LongInput","userInput"),px=c(600,300))
output$din_css=renderUI({
tags$head(
tags$style(HTML(paste0('
.selectize-input {
white-space: nowrap;
}',
paste(apply(df1,1,function(i){
paste0("#",i[["name"]],"+ div>.selectize-dropdown{
width: ",i[["px"]],"px !important;
}")
})
,collapse='/n') )
)
)
)
})
}
shinyApp(ui, server)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句