防止 selectInput 换行文本

Ada*_*m_G 5 r shiny

在闪亮的应用程序中,有没有办法防止下拉列表中的文本换行selectInput(),如下面的屏幕截图所示?每个选项都是一个长文本字符串。我希望下拉菜单在一行上显示每个长字符串,而不需要制作一个巨大的侧边栏。

在此输入图像描述

Sym*_*xAU 2

从这里这里获取灵感,您可以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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述