Prevent selectInput from wrapping text

前端 未结 2 1292
陌清茗
陌清茗 2020-12-18 09:58

In a shiny app, is there a way to prevent the text of the dropdown in selectInput() from wrapping, as in the screenshot below? Each option is a long text string

相关标签:
2条回答
  • 2020-12-18 10:45

    If you do selectize=False, within

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

    It will not wrap on your text.

    0 讨论(0)
  • 2020-12-18 10:59

    Taking inspiration from here and here you can add some custom css to the drowpdown

    Here's a working example

    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)
    

    0 讨论(0)
提交回复
热议问题