显示从列表输出中提取的多个表格
问题描述:
我使用一个函数返回了一个n数据框的列表:根据变量的层数,n是可变的。显示从列表输出中提取的多个表格
我想显示使用循环这n个表中server.R
这里是我的代码:
outlist2 <- reactive(label="toto", ({
if(is.null(input$datafile)){return()}
if(is.null(input$varinteret)
|| is.null(input$vartemps)
# ||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.comparer<-compareT0parproduit(data=data,y=input$varinteret,group=input$varprod,TemoinNametemps=input$checktempsref, group2 = input$vartemps)
}
}))
#
nblevels<-reactiveValues(filedata()[,input$varprod])
for (i in 1:nblevels){
output$uicomparetempsT0(i) <- shiny::renderTable({
outlist2()$res.comparer[[i]]
和ui.R
shiny::tableOutput("uicomparetempsT0")
而且我的错误消息
Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
Stack trace (innermost first):
44: .getReactiveEnvironment()$currentContext
43: .dependents$register
42: filedata
41: reactiveValues
40: server [C:\Users\itm\Desktop\Documents\appli Clarins test/server.R#454]
1: shiny::runApp
Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
答
好, 我想这行代码: 启发这个链接:https://gist.github.com/wch/5436415/
observe(
outlist2 <- reactive(label="toto", ({
if(is.null(input$datafile)){return()}
if(is.null(input$varinteret)
&& is.null(input$vartemps)
&& is.null(input$apparie)
&& s.null(input$tempsrefouinon)
&&is.null(input$prodrefouinon)
&&is.null(input$checkprod)
&&is.null(input$checkprodref)
)
{return()}
else
{
data<-filedata()
res.comparer<-compareT0parproduit(data=data,y=input$varinteret,group=input$varprod,TemoinNametemps=input$checktempsref, group2 = input$vartemps)
# res.comparer<-list(data(), data())
}
}))
#
)
nblevels<-reactive({
if(is.null(input$datafile)){return()}
if((is.null(input$varprod))&&(is.null(input$vartemps))) {return()}
data<-filedata()
res<-nlevels(data[,input$varprod])
})
output$plots <- renderUI({
if(is.null(input$datafile)){return()}
if((is.null(input$varprod))&&(is.null(input$vartemps))) {return()}
#
else {
# table_output_list <- lapply(1:nlevels(data()[,input$varprod]), function(i) {
table_output_list <- lapply(1:nblevels, function(i) {
plotname <- paste("table", i)
tableOutput(plotname)
})
# Convert the list to a tagList - this is necessary for the list of items
# to display properly.
do.call(tagList, table_output_list)
}
})
for (i in 1:nblevels)
{
# Need local so that each item gets its own number. Without it, the value
# of i in the renderPlot() will be the same across all instances, because
# of when the expression is evaluated.
local({
my_i <- i
plotname <- paste("table", my_i, sep="")
output[[plotname]] <- renderTable({
res2<-outlist2()
res2$res.comparer[[my_i]]
})
})
}
1 tableOutput只能输出1个表。不是多个。 – GAURAV
谢谢Gaurav, 但它是唯一的一个数据表。 outlist2()$ res.comparer [[i]]是一个表。 –