Shiny - 如何渲染两个基于相同反应数据帧的对象?
Shiny - How can I render two objects that are both based on the same reactive data frame?
我正在用 Shiny 创建一个应用程序。我需要它做的一件事是显示一个箱线图,该箱线图总结了一个基于用户输入的子集的数据框。这是我用来对此处的数据框进行子集化的一些代码:由于保密协议,我无法提供数据源。
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 用于另一个 table,如果我可以将子集代码置于反应函数之上,这将使代码更整洁、更易于阅读。但是,我无法让整个代码块按原样响应,因为 return 没有一个值。如果我尝试在反应函数中使用此代码块,然后稍后将其作为 function() 调用,我会收到 "object of type 'closure' is not subsettable" 错误。有什么方法可以使这个反应式代码 return plotdata 以一种我可以在单个 renderPlot 之外使用它的方式吗?
很抱歉这无法重现,但如果您能从理论上告诉我 how/if 我可以做到,那将不胜感激。
问题是您想要return plotdata 和textout 吗?然后做:return(list(plotdata, textout))
然后:
a <- myreactive()
plotdata <- a[[1]]
textout <- a[[2]]
我正在用 Shiny 创建一个应用程序。我需要它做的一件事是显示一个箱线图,该箱线图总结了一个基于用户输入的子集的数据框。这是我用来对此处的数据框进行子集化的一些代码:由于保密协议,我无法提供数据源。
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 用于另一个 table,如果我可以将子集代码置于反应函数之上,这将使代码更整洁、更易于阅读。但是,我无法让整个代码块按原样响应,因为 return 没有一个值。如果我尝试在反应函数中使用此代码块,然后稍后将其作为 function() 调用,我会收到 "object of type 'closure' is not subsettable" 错误。有什么方法可以使这个反应式代码 return plotdata 以一种我可以在单个 renderPlot 之外使用它的方式吗?
很抱歉这无法重现,但如果您能从理论上告诉我 how/if 我可以做到,那将不胜感激。
问题是您想要return plotdata 和textout 吗?然后做:return(list(plotdata, textout))
然后:
a <- myreactive()
plotdata <- a[[1]]
textout <- a[[2]]