阻止selectInput包装文本

时间:2016-05-10 23:44:10

标签: r shiny

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

enter image description here

2 个答案:

答案 0 :(得分:1)

herehere获取灵感,您可以向drowpdown添加一些自定义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)

enter image description here

答案 1 :(得分:1)

如果您在{p>

selectize=False

它不会自动换行。