【问题标题】:Improve app speed with `pickerInput` size options使用 `pickerInput` 大小选项提高应用程序速度
【发布时间】:2019-08-28 21:07:54
【问题描述】:

我正在使用shinyWidgets 包开发一个闪亮的应用程序来完成我的selectInput。 对于导致一些错误的输入变量,我有许多模式。 我减小了picker(大小参数)的大小,如果可能的话,只显示10个变量的第一个选项并激活l​​iveSearch选项。但似乎不起作用...

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)

在此示例中,我只想显示前 10 个值(但如果我搜索它们可以找到其他值)。我想去掉滚动条,可以吗?

【问题讨论】:

  • 您好,Mostafa,请添加一个 min reprex
  • 嗨,Eli,已经完成了,您可以查看更新

标签: shiny shinywidgets


【解决方案1】:

我在 ui 中添加了这个:

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

完整代码:

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)

【讨论】:

  • 当然,Chrome DevTools 是你的朋友。对于玩 CSS 非常有用。
猜你喜欢
  • 2018-03-20
  • 2016-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多