Mostafa90
Mostafa90

Reputation: 1706

Improve app speed with `pickerInput` size options

I 'm developping a Shiny App with the shinyWidgets package for doing my selectInput. I have many modalities for the inputs variable which cause some bugs. I reduced the size of the picker (size argument) and if possible show only 10 first options of variables and activate the liveSearch option. But not seems to work ...

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  pickerInput(
    inputId = "somevalue1", 
    label = "somevalue1",         
    choices = NULL,
    multiple = TRUE,
    selected = NULL,
    options = list(
      `actions-box` = TRUE,
      size = 10,
      `live-search` = TRUE
    )
  ),
  pickerInput(
    inputId = "somevalue2", 
    label = "somevalue2",         
    choices = NULL,
    multiple = TRUE,
    selected = NULL,
    options = list(
      `actions-box` = TRUE,
      size = 10,
      `live-search` = TRUE
    )
  )
)
server <- function(input, output, session) {
  observe({
    updatePickerInput(
      session = session,
      inputId = "somevalue1",
      choices = 1:1000
    )
  })

  observe({
    if (!is.null(input$somevalue1))
      choices <- which(input$somevalue1 %in% 1:1000)
    else
      choices <- 1:1000

    updatePickerInput(
      session = session,
      inputId = "somevalue2",
      choices = choices
    )
  })
}

shinyApp(ui, server)

In this example I want to show only the first 10 value (but could find others if I search them). I want to remove the scroll bar, is it possible ?

Upvotes: 1

Views: 604

Answers (1)

Eli Berkow
Eli Berkow

Reputation: 2725

I added this to the ui:

,tags$head(
    tags$style(
        '.inner.open {
            overflow-y: hidden !important;
        }'
    )
)

Full code:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
    pickerInput(
        inputId = "somevalue1", 
        label = "somevalue1",         
        choices = NULL,
        multiple = TRUE,
        selected = NULL,
        options = list(
            `actions-box` = TRUE,
            size = 10,
            `live-search` = TRUE
        )
    ),
    pickerInput(
        inputId = "somevalue2", 
        label = "somevalue2",         
        choices = NULL,
        multiple = TRUE,
        selected = NULL,
        options = list(
            `actions-box` = TRUE,
            size = 10,
            `live-search` = TRUE
        )
    ),
    tags$head(
        tags$style(
            '.inner.open {
                overflow-y: hidden !important;
            }'
        )
    )
)
server <- function(input, output, session) {
    observe({
        updatePickerInput(
            session = session,
            inputId = "somevalue1",
            choices = 1:1000
        )
    })

    observe({
        if (!is.null(input$somevalue1))
            choices <- which(input$somevalue1 %in% 1:1000)
        else
            choices <- 1:1000

        updatePickerInput(
            session = session,
            inputId = "somevalue2",
            choices = choices
        )
    })
}

shinyApp(ui, server)

Upvotes: 1

Related Questions