使用“pickerInput”大小选项提高应用程序速度
Improve app speed with `pickerInput` size options
我正在使用 shinyWidgets
软件包开发一个闪亮的应用程序来完成我的 selectInput
。
我有很多输入变量的模式,这会导致一些错误。
我减小了 picker
(大小参数)的大小,如果可能,只显示 10 个变量的第一个选项并激活 liveSearch 选项。但似乎不起作用...
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 个值(但如果我搜索它们,可以找到其他值)。我想去掉滚动条,可以吗?
我将此添加到 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)
我正在使用 shinyWidgets
软件包开发一个闪亮的应用程序来完成我的 selectInput
。
我有很多输入变量的模式,这会导致一些错误。
我减小了 picker
(大小参数)的大小,如果可能,只显示 10 个变量的第一个选项并激活 liveSearch 选项。但似乎不起作用...
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 个值(但如果我搜索它们,可以找到其他值)。我想去掉滚动条,可以吗?
我将此添加到 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)