我有一个闪亮的应用如下:
我的目标是能够从SelectInput UI功能的类型列中过滤多个值。当我做
时 selectInput(inputId, label, choices, multiple = TRUE)
,过滤不起作用,因为它期望有1个响应。
下面是工作版本,但我不知道如何在selectInput中使用多个功能。
我目前正在使用
test1<-filter(test, `Type`==input$file4)
当我将此扩展名添加到multiple=TRUE
服务器
library(shiny)
library(readr)
library(dplyr)
library(DT)
actor <- c('Matt Damon','George Clooney','Brad Pitt', 'Clive Owen', 'Morgan Freeman', 'Edward Norton', 'Adrian Granier')
category<-c('action', 'action', 'noir', 'action', 'thriller', 'noir', 'action')
movie <- c('Oceans Eleven', 'Oceans Twelve', 'Fight Club', 'Children of Men', 'The Shawshank Redemption', 'American History X', 'Entourage')
movies <- c(21, 23, 26, 12, 90, 14, 1)
cost <- c(210000, 2300000, 260000, 120000, 90000, 140000, 10000)
Type <- c('A','B','C', 'A', 'B', 'C', 'A')
moviedata<-data.frame(actor, category, movie, movies, cost, Type)
shinyServer(function(input,output){
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
read_csv(file=file1$datapath)
})
output$sum <- renderDataTable({
if(is.null(data())){return ()}
test<-subset(moviedata, category %in% data()[[1]])
test1<-filter(test, `Type`==input$file4)
test1$`BUDGET`<-input$file5
test1$CHECKING<-ifelse(test1$`BUDGET`>test1$cost,"YES", "NO")
filter(test1, CHECKING=="YES")
})
output$tb <- renderUI({
if(is.null(data()))
h5("Powered by", tags$img(src='optimatic.png'))
else
tabsetPanel(tabPanel("Summary", dataTableOutput("sum")))
})
}
)
ui
library(shiny)
shinyUI(fluidPage(
titlePanel("Actor Finder"),
sidebarLayout(
sidebarPanel(
fileInput("file","Upload Category List: Must have category as header"),
selectInput("file4", "Select Type", c("A" = "A",
"B" = "B",
"C" = "C"), selected = "A",
multiple=FALSE),
numericInput("file5", "Choose cost", 1000000000),
tags$hr()),
mainPanel(
uiOutput("tb")
)
)
))
任何帮助都会很棒,谢谢!
在多个选择上过滤时,您无法使用==
,因为有选定值的列表。您可以改用%in%
:
test1<-filter(test, Type %in% input$file4)
要在Na中包含丢失的值,您可以将"缺失"选择添加到文件4然后:
:test1<-filter(test, Type %in% input$file4 |
(is.na(Type) & "Missing" %in% input$file4 ))