react 物: invalid (NULL) left side of assignment

标签 r shiny

我正在尝试提取称为tests.stats()的个人功能的输出

我用return语句创建一个函数:

   return(c(list.test.1, list.test.2 ,list.test.3, list.test.4))

其中每个list.test.<i>是一个list对象。

在 Shiny 的服务器中:
 outlist() <- reactive({
   if(is.null(input$datafile)){
     return()
   }
   if(is.null(input$varinteret)
      &&is.null(input$vartemps)
      &&is.null(input$varsujet)
      &&is.null(input$varprod) 
      &&is.null(input$apparie)
      &&is.null(input$tempsrefouinon)
      &&is.null(input$prodrefouinon)
      &&is.null(input$checkprod)
      &&is.null(input$checkprodref)){
     return()
   } else {
     data<-filedata()
     res <- tests.stats(data = data(),
              y = input$varinteret, 
              group = input$varprod, 
              group2 = input$vartemps, 
              sujet = input$varsujet, 
              apparie = input$apparie, 
              temoin = input$prodrefouinon, 
              TemoinName = input$checkprodref)
   }  

和错误消息:
Warning: Error in <-: invalid (NULL) left side of assignment
Stack trace (innermost first):
    40: server [C:\Users\itm\Desktop\Documents\appli/server.R#357]
     1: shiny::runApp
Error in outlist() <- reactive({ : invalid (NULL) left side of assignment

为什么会收到此错误?

最佳答案

发生这种情况的原因是:

outlist() <- reactive({...})

这是不正确的语法,因为您告诉Shiny outlist是已经定义的响应式(Reactive)表达式,应该对其进行求值。然后,您尝试使用Shiny无法理解的语法为该响应式(Reactive)表达式分配某些内容。

因此,如果您改为使用:
outlist <- reactive({...})

现在,您已经正确地将outlist定义为可响应的Shiny对象,可以在代码中的其他位置使用outlist()对其进行调用。

该主题的文档非常好,可以在这里找到:

http://shiny.rstudio.com/reference/shiny/latest/reactive.html

http://shiny.rstudio.com/tutorial/lesson6/

似乎您也可以使用validateneed来处理需要输入的内容:

http://shiny.rstudio.com/articles/validation.html

以及哈德利勋爵(Lord Hadley)提供的代码样式指南:

http://adv-r.had.co.nz/Style.html

关于 react 物: invalid (NULL) left side of assignment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35769388/

相关文章:

r - GGanimate:具有数值的 geom_text 以十进制数字而不是整数进行动画

尝试下载文件时,R CMD 检查在 ubuntu 上失败,但功能在 R 中有效

shiny - 异步 : Display progress when actionButton is hit and disable other operations for the same user but allow concurrent users

r - 在 Shiny, R 中列出 Leaflet map 的所有可用 Font Awesome 图标

r - 错误: unused arguments in Shiny (R)

r - 用文本 : ggplot2 标记最小和最大比例填充渐变图例

r - 查找 R 中重叠开始日期和结束日期的所有日期范围

r - 根据直接和间接关系对个人进行分组

r - 在 Shiny 的服务器上增加堆栈维度

R Shiny : checkBox format