微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在 RShiny 中提取反应值

如何解决无法在 RShiny 中提取反应值

当我运行我的服务器函数时收到一条错误消息,内容为:**“错误:在没有活动响应上下文的情况下不允许操作。

  • 您试图做一些只能从反应性消费者内部完成的事情。"**

谁能告诉我为什么我的反应式代码会产生那个错误

这是我的非响应式服务器:

server <- function(input,output){
  reactivedata <- reactive({PC 
  })
  x <- reactive({reactivedata() %>% drop_na() %>% pull(plotdate)})
  y <- reactive({
    reactivedata() %>% pull(Value) %>% na.omit()
  })
  
  ###Non-reactive code
  
  for (d in 1:c){
    tempval <- val[which(!is.na(val[,d])),d] #omit not filled rows na
    tempdate <- rollingdates[,d]
    se <- sd(tempval)
    mean <- mean(tempval)
    movrang <- diff(tempval)
    rbar <- mean(abs(movrang))
    d2constant <- 1.1283791671
    sigmacalc <- rbar/d2constant

    if (percent1 >= 0.02){
      rc <- rc + 1
      if (!is.na(usl) && !is.na(lsl) == TRUE){
        ppkcalc <- c(((usl-mean)/(3*sigmacalc)),((mean-lsl)/(3*sigmacalc)))
        ppk <- min(ppkcalc)
      }else if (is.na(usl) == TRUE){
        ppk <- ((mean-lsl)/(3*sigmacalc))
      }else if (is.na(lsl) == TRUE){
        ppk <- ((usl-mean)/(3*sigmacalc))
      }

      PC$Parameter[rc] <- param
      PC$Calculation[rc] <- "ppk"
      PC$Value[rc] <- ppk
      PC$DaterangeBeg[rc] <- as.character(tempdate[length(which(!is.na(tempdate)))])
      PC$DaterangeEnd[rc] <- as.character(rollingdates[1,d])
      PC$plotdate <- paste(PC$DaterangeBeg,PC$DaterangeEnd,sep="  ")
    }
  }
  PC = na.omit(PC)
}

这里有几乎相同的代码,但以反应形式制作(我正在反应地提取 usl、lsl、ucl 和 lcl 值。 这是我的响应式服务器:

server <- function(input,output){
  reactivedata <- reactive({PC 
  })
  x <- reactive({reactivedata() %>% drop_na() %>% pull(plotdate)})
  y <- reactive({
    reactivedata() %>% pull(Value) %>% na.omit()
  })
 
  
  ###Reactive Code 

  
  ucl =reactive({excel[excel$Quality.Attributes == input$select,"UCL"]})
  lcl =reactive({excel[excel$Quality.Attributes == input$select,"LCL"]})
  usl =reactive({excel[excel$Quality.Attributes == input$select,"USL"]})
  lsl =reactive({excel[excel$Quality.Attributes == input$select,"LSL"]})
  # #
  # 
  # 
  for (d in 1:c){
     tempval <- val[which(!is.na(val[,d] #omit not filled rows na
     tempdate <- rollingdates[,d]
     se <- sd(tempval)
     mean <- mean(tempval)
     movrang <- diff(tempval)
     rbar <- mean(abs(movrang))
     d2constant <- 1.1283791671
     sigmacalc <- rbar/d2constant
      
   if (percent1 >= 0.02){
       rc <- rc + 1
     if (!is.na(usl()) && !is.na(lsl()) == TRUE){
     ppkcalc <- c((usl()-mean/(3*sigmacalc)),((mean-lsl())/(3*sigmacalc)))
       ppk <- min(cpkcalc)
     }else if (is.na(usl()) == TRUE){
       ppk <- ((mean-lsl())/(3*sigmacalc))
     }else if (is.na(lsl()) == TRUE){
       ppk <- ((usl()-mean)/(3*sigmacalc))
    }
  # 
  # 
       PC$Parameter[rc] <- param
       PC$Calculation[rc] <- "ppk"
       PC$Value[rc] <- ppk
       PC$DaterangeBeg[rc] <- as.character(tempdate[length(which(!is.na(tempdate)))])
       PC$DaterangeEnd[rc] <- as.character(rollingdates[1,d])
       PC$plotdate <- paste(PC$DaterangeBeg,sep="  ")
   }
   }
   PC = na.omit(PC)
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。