R 闪亮-如何渲染基于同一反应数据帧的两个对象?
我正在用Shiny创建一个应用程序。我需要它做的一件事是显示一个箱线图,该箱线图总结了基于用户输入的子集数据帧。以下是我用来将数据框子集的一些代码:由于NDA,我无法提供数据源R 闪亮-如何渲染基于同一反应数据帧的两个对象?,r,function,shiny,conditional-statements,R,Function,Shiny,Conditional Statements,我正在用Shiny创建一个应用程序。我需要它做的一件事是显示一个箱线图,该箱线图总结了基于用户输入的子集数据帧。以下是我用来将数据框子集的一些代码:由于NDA,我无法提供数据源 newone <- subset(mydata, mydata$ShippingCondition==input$mode) if (input$mode=="Truck"){ if (input$zipwhse == 0){ newtwo<- subset(newone, newo
newone <- subset(mydata, mydata$ShippingCondition==input$mode)
if (input$mode=="Truck"){
if (input$zipwhse == 0){
newtwo<- subset(newone, newone$totalmiles>=(inmiles-100) & newone$totalmiles<=(inmiles+100) & newone$Qty_KG>=(input$qty-2000) & newone$Qty_KG<=(input$qty+2000) & newone$manufacturingzip == newone$shipfromzip)
newthree<-subset(newtwo, newtwo$BUGroup==new_bugroup)
if (nrow(newthree)< 10) {
plotdata<-newtwo
textout<-"Truck Shipments that are not warehoused. They traveled a distance within +/- 100 miles, and weigh within +/- 2,000 kg of the current shipment."
} else {
newfour<-subset(newthree, newthree$ContainerReq==input&containerreq)
if (nrow(newfour)< 10) {
plotdata<-newthree
textout<-sprintf("Truck shipments of %s that are not warehoused. They traveled a distance within +/- 100 miles, and weigh within +/- 2,000 kg of the current shipment.", input$bugroup)
}
else {
plotdata<-newfour
textout<-sprintf("Truck shipments of %s that are not warehoused. They traveled a distance within +/- 100 miles, and weigh within +/- 2,000 kg of the current shipment, as well as have the same container requirements.", input$containerreq)}
}
}
……等等
打印的最终数据帧称为plotdata,关联的文本称为textout
问题是,我还需要为另一个表使用plotdata,如果我能将子集代码设置在反应函数之上,这将使代码更整洁、更易于阅读。然而,我不能让整个代码块像现在这样反应,因为没有一个值可以返回。如果我尝试在反应函数中使用这段代码,然后将其作为函数调用,我会得到类型为“closure”的对象不可再附加错误。是否有某种方法可以使此反应式代码返回plotdata,使其在单个renderPlot之外使用
很抱歉,这是不可复制的,但如果你能从理论上告诉我如何/如果我能做到,我将不胜感激 问题是您希望同时返回plotdata和textout吗?然后执行:returnlistplotdata,textout 然后:
a <- myreactive()
plotdata <- a[[1]]
textout <- a[[2]]