示例:
以下闪亮示例ValueError: matrix_multiply: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (m,n),(n,p)->(m,p) (size 100 is different from 1)
文件包含app.R
UI。可以使用selectizeInput
删除所选元素。
options = list(plugins= list('remove_button'))
问题:
是否有一个selectize.js选项可以在闪亮中访问,它会添加一个功能“删除所有一次”而不是“逐个删除”,如示例所示? / p>
我研究了selectize.js docu,但卡住了。
答案 0 :(得分:4)
我认为解决方案是使用selected=
,但是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)
选项应该更改为minium(一个选项?)因为它是重置值
Reset
按下selected
按钮后,系统会立即清除所有selectizeInput
值,并返回 SELECT X.*
INTO NewTable
FROM
(
SELECT .... complex query ....
FROM ...
...
) AS X
的主要值。
答案 1 :(得分:0)
我在寻找其他东西时偶然发现了这个答案,这是我最近要解决的问题。这是我的解决方案,不需要额外的按钮。
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_button')
添加选项,但需要将其添加到ui
部分和updateSelectizeInput()
功能。