【问题标题】:Prevent selectInput from wrapping text防止 selectInput 换行
【发布时间】:2016-09-06 03:38:30
【问题描述】:

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

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    herehere 中汲取灵感,您可以在下拉菜单中添加一些自定义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)
    

    【讨论】:

    • 有没有办法为每个下拉菜单自定义这个?
    • 很可能是的,但我目前没有这个例子。可能值得提出一个单独的问题,以便更多人看到。
    • 好的,谢谢。问题贴在这里,如果你有兴趣stackoverflow.com/questions/37298498/…
    【解决方案2】:

    如果你做selectize=False,在

    selectInput(id="id",label="label",choices=your_choices, selectize=False)

    它不会在您的文本上换行。

    【讨论】:

      猜你喜欢
      • 2018-04-12
      • 2021-06-13
      • 2011-05-21
      • 1970-01-01
      • 2015-09-12
      • 2014-03-23
      • 2015-07-16
      • 2012-12-29
      • 1970-01-01
      相关资源
      最近更新 更多