R 带“功能”的闪亮selectizeInput;“一次移除所有组件”;
示例: 下面的示例R 带“功能”的闪亮selectizeInput;“一次移除所有组件”;,r,shiny,selectize.js,R,Shiny,Selectize.js,示例: 下面的示例app.R文件包含一个selectizeInputUI。可以使用options=list(plugins=list('remove_按钮'))删除所选元素 问题: 是否有一个selectize.js选项可以在Shining中访问,它添加了一个功能“一次删除所有内容”,而不是示例中所示的“逐个删除” 我研究了,但被卡住了。我认为绕行解决方案是使用reset\u按钮,但是selected=选项应该更改为minium(一个选项?),因为它是重置值 library(shiny) li
app.R
文件包含一个selectizeInput
UI。可以使用options=list(plugins=list('remove_按钮'))
删除所选元素
问题:
是否有一个selectize.js选项可以在Shining中访问,它添加了一个功能“一次删除所有内容”,而不是示例中所示的“逐个删除”
我研究了,但被卡住了。我认为绕行解决方案是使用
reset\u按钮
,但是selected=
选项应该更改为minium(一个选项?),因为它是重置值
library(shiny)
library(shinyjs)
library(dplyr)
ui= fluidPage(
sidebarLayout(
sidebarPanel(
useShinyjs(),
div(id = "form",
selectizeInput(inputId = "cyl",
label = "cyl",
choices = sort(unique(mtcars$cyl)),
selected=sort(unique(mtcars$cyl))[1], multiple=TRUE)),
actionButton("reset_input", "Reset")
),
mainPanel(
tableOutput("tab")
)
)
)
server= function(input, output) {
observeEvent(input$reset_input, {
shinyjs::reset("form")
})
df_filtered= reactive({
mtcars %>%
{if (is.null(input$cyl)) . else filter(., cyl %in% input$cyl)}
})
output$tab= renderTable(df_filtered())
}
shinyApp(ui, server)
按下
Reset
按钮后,所有选择的值将立即清除,并返回selectizeInput
的主值。我在寻找其他内容时偶然发现了这个答案,这是我最近必须解决的问题。这是我的解决方案,它不需要额外的按钮
library(shiny)
library(shinyjs)
library(dplyr)
ui= fluidPage(
sidebarLayout(
sidebarPanel(
selectizeInput(inputId = "cyl",
label = "cyl",
choices = c("All", sort(unique(mtcars$cyl))),
multiple = TRUE,
options = list(placeholder = "All"))
),
mainPanel(
tableOutput("tab")
)
)
)
server= function(input, output) {
# This bit will revert the multi select back to the placeholder.
# You might want to change the filtering logic further down stream though (depending on what actually want to display).
observe({
if("All" %in% input$cyl) {
updateSelectizeInput(session = getDefaultReactiveDomain(),
"cyl",
choices = c("All", sort(unique(mtcars$cyl))),
options = list(placeholder = "All"))
}
})
df_filtered= reactive({
mtcars %>%
{if (is.null(input$cyl)) . else filter(., cyl %in% input$cyl)}
})
output$tab= renderTable(df_filtered())
}
shinyApp(ui, server)
您也可以将plugins=list('remove_按钮')
添加到选项中,但需要将其添加到ui
部分和updateSelectizeInput()中
函数。您希望它集成到表单中,还是下面的按钮就足够了?@BigDataScientist best case集成到表单中。如果没有人提出集成方式,我可以用非奇特的方式来帮助;)您可以按住删除按钮:)。说真的,我认为你运气不好。让BDS给你写一个按钮。我查看了代码,发现remove_按钮
功能相对较新,而且插件还不多。如果有人有雄心壮志,他们当然可以编写一个新的插件来完成这项工作,但感觉这将是一个混乱的代码。@MikeWise thx感谢您的关注。谢谢你的判断。谢谢。这个解决方案在功能上是可行的,不幸的是,它添加了一个我需要避免的按钮。我一直在寻找一种整合在表单中的解决方案。谢谢你的贡献和花费的时间。
library(shiny)
library(shinyjs)
library(dplyr)
ui= fluidPage(
sidebarLayout(
sidebarPanel(
selectizeInput(inputId = "cyl",
label = "cyl",
choices = c("All", sort(unique(mtcars$cyl))),
multiple = TRUE,
options = list(placeholder = "All"))
),
mainPanel(
tableOutput("tab")
)
)
)
server= function(input, output) {
# This bit will revert the multi select back to the placeholder.
# You might want to change the filtering logic further down stream though (depending on what actually want to display).
observe({
if("All" %in% input$cyl) {
updateSelectizeInput(session = getDefaultReactiveDomain(),
"cyl",
choices = c("All", sort(unique(mtcars$cyl))),
options = list(placeholder = "All"))
}
})
df_filtered= reactive({
mtcars %>%
{if (is.null(input$cyl)) . else filter(., cyl %in% input$cyl)}
})
output$tab= renderTable(df_filtered())
}
shinyApp(ui, server)