Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在多个selectInput中出错_R_Drop Down Menu_Shiny - Fatal编程技术网

R 在多个selectInput中出错

R 在多个selectInput中出错,r,drop-down-menu,shiny,R,Drop Down Menu,Shiny,此应用程序旨在根据Shiny应用程序中的2个输入选择创建更大数据集的子集。我使用了在上找到的下拉按钮功能 服务器--> shinyServer(功能(输入、输出、会话){ 数据集-基于菜单选择的更改 df1Hi当您过滤数据时。frame使用%中的%而不是=,因为您比较的两个向量的长度不同,例如: df1 <- reactive({ df[df$OperatingUnit %in% input$check1 & df$indicator %in% input$check2, ]

此应用程序旨在根据Shiny应用程序中的2个输入选择创建更大数据集的子集。我使用了在上找到的下拉按钮功能

服务器-->

shinyServer(功能(输入、输出、会话){
数据集-基于菜单选择的更改

df1Hi当您过滤
数据时。frame
使用%
中的
%而不是
=
,因为您比较的两个向量的长度不同,例如:

df1 <- reactive({
  df[df$OperatingUnit %in% input$check1 & df$indicator %in% input$check2, ]
})

谢谢!
%in%
解决了第一个问题。对于第二个问题,我尝试只为ou执行selectAll,服务器代码有观察事件位。但是,当我单击selectAll按钮时,应用程序关闭,我得到以下错误:
警告:粘贴中的错误:找不到对象“ou”
P.S.已更正我的代码加载您的数据并创建
ou
global.R
ui.R
ou1 <- levels(df$OperatingUnit)
ou <- setNames(as.list(ou1),ou1)
indi1 <- levels(df$indicator)
indi <- setNames(as.list(indi1),indi1)

ui->...
inputPanel(
  dropdownButton(
  label = "Select OU", status = "default", width = 120, 
  actionButton(inputId = "all", label = "Select all"),
  checkboxGroupInput(inputId = "check1", label = "Choose", choices = paste(ou))
),
dropdownButton(
  label = "Select Indicators", status = "default", width = 150, 
  checkboxGroupInput(inputId = "check2", label = "Choose", choices = paste(indi))
),

tableOutput("tab1")

))
shinyServer(function(input, output, session) {

dataset - changes based on menu selections
 df1 <- reactive({
  df[df$OperatingUnit==input$check1 & df$indicator==input$check2,]
})

output$tab1<- renderTable({
 head(df1(), n = 10)
})

output$downloadData <- downloadHandler(
 filename = function() { 
  paste("PSNU_IM", '.csv', sep='') 
},
content = function(file) {
  write.csv(df1(), file)
}
 )

# Select all / Unselect all
observeEvent(input$all, {
if (is.null(input$check1)) {
  updateCheckboxGroupInput(
    session = session, inputId = "check1", selected = paste(ou)
  )
} else {
  updateCheckboxGroupInput(
    session = session, inputId = "check1", selected = ""
    )
   }
  })
 })
)`
structure(list(Region = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L), .Label = "Africa", class = "factor"), OperatingUnit = structure(c(3L, 
3L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L), .Label = c("Angola", "Botswana", 
"Cameroon"), class = "factor"), SNU1Uid = structure(c(5L, 5L, 
9L, 9L, 4L, 5L, 1L, 4L, 5L, 4L, 4L, 5L, 4L, 9L, 3L, 9L, 4L, 9L, 
4L, 4L, 4L, 3L, 4L, 4L, 5L, 5L, 9L, 5L, 4L, 4L, 3L, 3L, 9L, 4L, 
4L, 9L, 4L, 7L, 8L, 6L, 2L), .Label = c("", "BTRiZA58YEx", "HxXMyMSODnm", 
"IaFLxtEwIwk", "Jm3YTCERxvX", "MERiZA58YEx", "MTRiZA58YEx", "MTRiZA68YEx", 
"MTRiZG58YEx"), class = "factor"), PSNUuid = structure(c(29L, 
11L, 23L, 23L, 10L, 29L, 1L, 13L, 18L, 30L, 8L, 2L, 9L, 7L, 15L, 
19L, 33L, 16L, 27L, 31L, 21L, 3L, 20L, 25L, 14L, 32L, 7L, 28L, 
22L, 22L, 24L, 12L, 16L, 8L, 9L, 5L, 10L, 4L, 6L, 17L, 26L), .Label = c("", 
"a2nQs7VmYiD", "AbJXFBhkc4U", "AFX0cjkDX6A", "AFX0djkDX6A", "AFX0djkFX6A", 
"AW764lDxjdr", "clasYX5teTV", "fHkrk3yL1uU", "gOaZeiwAoCD", "GP5qeoiXMtA", 
"hvNtuMClAXW", "hz2Tdvrxqbp", "JIcgSOsSpSV", "js5vRAkkqxB", "k7lIVnxWbm7", 
"KFX0djkDX6A", "MIvAFWhI9Yc", "Ns6ZJi0iwJj", "oAgxCCStCQe", "PJKaNADvNfi", 
"r5xWCJ4ZqYQ", "rjDWLPMhaY0", "VaHOXJU4rir", "vewKgey8sOW", "VFX0djkDX6A", 
"Vq1CnJNw46x", "vqaBeYFtUn0", "VZPPWeDuJqU", "YuCzvkHV2X5", "YXiMSh7CqES", 
"zU7eKPwFr69", "ZxJNWnk4hYW"), class = "factor"), indicator = structure(c(5L, 
5L, 1L, 5L, 1L, 1L, 4L, 1L, 1L, 2L, 5L, 1L, 1L, 5L, 1L, 5L, 5L, 
5L, 5L, 3L, 1L, 5L, 1L, 1L, 5L, 5L, 1L, 5L, 1L, 3L, 1L, 1L, 5L, 
5L, 1L, 5L, 5L, 6L, 6L, 5L, 5L), .Label = c("CARE_CURR", "GEND_GBV", 
"GEND_NORM", "HRH_PRE", "TX_CURR", "TX_NEW"), class = "factor"), 
    numeratorDenom = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L), .Label = "N", class = "factor"), indicatorType = structure(c(1L, 
    1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 
    1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 
    2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L), .Label = c("DSD", 
    "TA"), class = "factor"), disaggregate = structure(c(4L, 
    1L, 1L, 6L, 6L, 1L, 5L, 1L, 2L, 1L, 6L, 1L, 1L, 3L, 1L, 6L, 
    6L, 1L, 1L, 6L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Age/Sex", 
    "Age/Sex Aggregated", "Age/Sex, Aggregated", "Aggregated Age/Sex", 
    "Grad Cadre", "Total Numerator"), class = "factor"), categoryOptionComboName = structure(c(8L, 
    7L, 16L, 13L, 13L, 23L, 19L, 14L, 9L, 3L, 13L, 16L, 21L, 
    2L, 17L, 13L, 13L, 2L, 11L, 13L, 18L, 1L, 14L, 4L, 1L, 10L, 
    23L, 12L, 20L, 6L, 22L, 15L, 7L, 12L, 16L, 5L, 2L, 12L, 16L, 
    5L, 2L), .Label = c("<1, Female", "<1, Male", "<10, Female", 
    "<15, Male", "1-4, Male", "10-14, Male", "15-19, Female", 
    "15+, Female", "15+, Male", "20+, Female", "20+, Male", "5-14, Male", 
    "default", "Female, 15-19", "Female, 20-24", "Female, 25-49", 
    "Female, 5-9", "Female, 50+", "Lab Professionals", "Male, <1", 
    "Male, 1-4", "Male, 20-24", "Male, 50+"), class = "factor"), 
    Age = structure(c(10L, 9L, 13L, 1L, 1L, 14L, 1L, 9L, 10L, 
    3L, 1L, 13L, 5L, 2L, 6L, 1L, 1L, 2L, 12L, 1L, 14L, 2L, 9L, 
    4L, 2L, 12L, 14L, 7L, 2L, 8L, 11L, 11L, 9L, 7L, 13L, 5L, 
    2L, 7L, 13L, 5L, 2L), .Label = c("  ", "  <01", "  <10", 
    "  <15", "  01-04", "  05-09", "  05-14", "  10-14", "  15-19", 
    "  15+", "  20-24", "  20+", "  25-49", "  50+"), class = "factor"), 
    Sex = structure(c(2L, 2L, 2L, 1L, 1L, 3L, 1L, 2L, 3L, 2L, 
    1L, 2L, 3L, 3L, 2L, 1L, 1L, 3L, 3L, 1L, 2L, 2L, 2L, 3L, 2L, 
    2L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 
    3L), .Label = c("", "Female", "Male"), class = "factor"), 
    FY2016Q4 = c(60L, 42L, 144L, 606L, 977L, 509L, 475L, 827L, 
    455L, 966L, 432L, 372L, 333L, 0L, 583L, 339L, 423L, 107L, 
    341L, 45L, 818L, 299L, 679L, 261L, 964L, 338L, 470L, 879L, 
    421L, 351L, 490L, 464L, 416L, 844L, 752L, 708L, 506L, 889L, 
    230L, 586L, 576L), FY2016APR = c(4L, 471L, 106L, 876L, 873L, 
    490L, 65L, 360L, 232L, 673L, 646L, 548L, 495L, 846L, 215L, 
    11L, 405L, 953L, 411L, 610L, 907L, 755L, 580L, 967L, 594L, 
    213L, 227L, 54L, 25L, 930L, 266L, 512L, 277L, 150L, 454L, 
    478L, 720L, 666L, 249L, 886L, 781L), FY2017_TARGETS = c(464L, 
    853L, 907L, 598L, 685L, 791L, 232L, 981L, 217L, 705L, 920L, 
    890L, 144L, 545L, 159L, 615L, 72L, 570L, 325L, 138L, 919L, 
    743L, 316L, 673L, 867L, 488L, 652L, 683L, 805L, 616L, 701L, 
    911L, 985L, 595L, 576L, 132L, 396L, 856L, 721L, 353L, 105L
    )), .Names = c("Region", "OperatingUnit", "SNU1Uid", "PSNUuid", 
"indicator", "numeratorDenom", "indicatorType", "disaggregate", 
"categoryOptionComboName", "Age", "Sex", "FY2016Q4", "FY2016APR", 
"FY2017_TARGETS"), class = "data.frame", row.names = c(NA, -41L
))
df1 <- reactive({
  df[df$OperatingUnit %in% input$check1 & df$indicator %in% input$check2, ]
})
observeEvent(input$all1, {
  if (is.null(input$check2)) {
    updateCheckboxGroupInput(
      session = session, inputId = "check2", selected = paste(indi)
    )
  } else {
    updateCheckboxGroupInput(
      session = session, inputId = "check2", selected = ""
    )
  }
})