目前,我正在尝试使用单个 uiOutput() 将我通过 api 调用检索到的多个表输出到仪表板页面上。
从这篇文章中获得了一些参考: R Shiny - Display multiple plots selected with checkboxGroupInput
然而,虽然我成功地将其放入整体布局的列表并将其输出到 uioutput() 中,但由于所有表都相同,我无法达到预期的结果,实际上它应该是不同的,因为我有已经为每个 renderdatatable() 标记了一个唯一的数据框,下面显示了屏幕截图和代码。在这里会很感激一些帮助谢谢![1]:https ://i.stack.imgur.com/W0B26.png
library(httr)
library(jsonlite)
library(plyr)
library(data.table)
library(rlist)
library(shiny)
########### UI ############
ui <- fluidPage(uiOutput('datatables'))
######### SERVER ###########3
server <- function(input, output, session){
output$datatables <- renderUI({
link <- 'https://api.zapper.fi/v1/protocols/balances/supported?addresses%5B%5D=0x58bbae0159117a75225e72d941dbe35ffd99f894&api_key=96e0cc51-a62e-42ca-acee-910ea7d2a241'
test <- GET(link)
test <- fromJSON(rawToChar(test$content))
counter1 <- 0
out <- list()
df <- list()
for (i in seq(from = 1, to = length(test$network))){
network <- test$network[i]
#counter <- counter + 1
out <- list(out, h2(paste0(str_to_title(network),' Network')))
for (e in ldply(test$protocols[i], data.frame)$protocol){
link1 <- paste0(paste0('https://api.zapper.fi/v1/protocols/',e),paste0(paste0('/balances?addresses%5B%5D=0x58bbae0159117a75225e72d941dbe35ffd99f894&network=',network),'&api_key=96e0cc51-a62e-42ca-acee-910ea7d2a241'))
data <- fromJSON(rawToChar(GET(link1)$content))
wallet <- '0x58bbae0159117a75225e72d941dbe35ffd99f894'
#info <- ldply(eval(parse(text=sprintf("data$'%s'$products$assets",wallet))),data.frame)
out <- list(out, h3(paste0(str_to_title(e),' Protocol')))
counter1 <- counter1 + 1
df[[counter1]] <- ldply(eval(parse(text=sprintf("data$'%s'$products$assets",wallet))),data.frame)
out<- list(out, renderDataTable(df[[counter1]]))
}
}
return(out)
})
}
shinyApp(ui, server)
更新:我还尝试将其包装在 OBSERVE() 和 LOCAL () 中以获得不同的输出,但仍然没有达到预期的结果,所有相同的表格都是错误的