闪亮:使用pickerInput和DataTable连接并显示多个过滤器
我试图确定一种连接多个过滤器并显示多行的方法。我试图使用pickerInput对不同的变量进行多个选择。当我选择“全选”时,只显示一个项目,即第一行“马自达RX4”。似乎我在服务器端缺少了一些东西,这些东西将连接多个选择以显示在选择多个变量和获取多个行时满足所需条件的多个行闪亮:使用pickerInput和DataTable连接并显示多个过滤器,r,dplyr,shiny,shinywidgets,R,Dplyr,Shiny,Shinywidgets,我试图确定一种连接多个过滤器并显示多行的方法。我试图使用pickerInput对不同的变量进行多个选择。当我选择“全选”时,只显示一个项目,即第一行“马自达RX4”。似乎我在服务器端缺少了一些东西,这些东西将连接多个选择以显示在选择多个变量和获取多个行时满足所需条件的多个行 library(shiny) library(shinyWidgets) library(DT) library(dplyr) mtcars <- mtcars[, c(1:5)] mpg <- mtcars[
library(shiny)
library(shinyWidgets)
library(DT)
library(dplyr)
mtcars <- mtcars[, c(1:5)]
mpg <- mtcars[,2]
cyl <- mtcars[,3]
disp <- mtcars[,4]
hp <- mtcars[,5]
ui <- fluidPage(
# Application title
titlePanel("Cars Information"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "mpg",
label = "Choose MPG:",
choices = c(unique(mtcars$mpg)),
options = list(`actions-box` = TRUE),multiple = T),
pickerInput(inputId = "cyl",
label = "Choose a cylinder:",
choices = c(unique(mtcars$cyl)),
options = list(`actions-box` = TRUE),multiple = T),
pickerInput(inputId = "disp",
label = "Choose a Displacement:",
choices = c(unique(mtcars$disp)),
options = list(`actions-box` = TRUE),multiple = T),
pickerInput(inputId = "hp",
label = "Choose a weight:",
choices = c(unique(mtcars$hp)),
options = list(`actions-box` = TRUE),multiple = T),
actionButton("view", "View Selection")
),
mainPanel(
DTOutput(outputId = "table")
)
)
)
# Define server logic
server <- function(input, output) {
datasetInput <- eventReactive(input$view,{
datasetInput <- filter(mtcars, mpg == input$mpg, cyl == input$cyl,
disp == input$disp, hp == input$hp)
return(datasetInput)
})
output$table <- renderDT({datasetInput()
}, colnames = c("Car Make/Model", "Miles per Gallon", "Cylinders", "Displacement", "Weight"))
}
# Run the application
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinyWidgets)
图书馆(DT)
图书馆(dplyr)
mtcars因为您的输入有multiple=T
,而不是在过滤器中使用=
,也许可以使用%in%
例如过滤器(mtcars,mpg%in%input$mpg,cyl%in%input$cyl.