【发布时间】:2016-09-06 03:38:30
【问题描述】:
在一个闪亮的应用程序中,有没有办法防止selectInput() 中的下拉文本换行,如下面的屏幕截图所示?每个选项都是一个长文本字符串。我希望下拉菜单在一行上显示每个长字符串,而不是制作巨大的侧边栏。
【问题讨论】:
在一个闪亮的应用程序中,有没有办法防止selectInput() 中的下拉文本换行,如下面的屏幕截图所示?每个选项都是一个长文本字符串。我希望下拉菜单在一行上显示每个长字符串,而不是制作巨大的侧边栏。
【问题讨论】:
从here 和here 中汲取灵感,您可以在下拉菜单中添加一些自定义css
这是一个工作示例
library(shiny)
server <- function(input, output) {
output$distPlot <- renderPlot({
hist(rnorm(input$obs), col = 'darkgray', border = 'white')
})
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100),
selectizeInput(inputId = "si",
label = "select",
choices = c("the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog"),
selected = NULL),
## Custom css
tags$head(
tags$style(HTML('
.selectize-input {
white-space: nowrap;
}
.selectize-dropdown {
width: 660px !important;
}'
)
)
)
),
mainPanel(plotOutput("distPlot"))
)
)
shinyApp(ui = ui, server = server)
【讨论】:
如果你做selectize=False,在
selectInput(id="id",label="label",choices=your_choices, selectize=False)
它不会在您的文本上换行。
【讨论】: