【发布时间】:2017-03-30 03:27:25
【问题描述】:
我不想指定单独的 fileInput 变量,而是使用 reactiveValues 来存储上传的 CSV 数据帧,以某种方式对其进行操作,然后存储它们以供以后加入。我的设计是通过文件名命名每个数据帧并附加到反应值rvTL。我的问题是,
- 如何访问我使用
reactiveValuesToList(rvTL)创建的列表下的各个数据框? - 下一步,如何创建
selectInput菜单以访问fileInput上传的各个数据帧
为了学习这个概念,我借鉴了 Dean Attali 的答案,并将 rvTL 与他的 values 变量相同。
R shiny: How to get an reactive data frame updated each time pressing an actionButton without creating a new reactive data frame?
我在reactiveValues 上浏览了许多示例代码,但仍不完全理解。大多数示例都在reactiveValuesToList(input) R Shiny: Keep/retain values of reactive inputs after modifying selection 上使用某种变体,我真的没有看到这里的逻辑。任何帮助/建议将不胜感激!
library(shiny)
runApp(shinyApp(
ui=(fluidPage(
titlePanel("amend data frame"),
mainPanel(
fileInput("file", "Upload file", multiple=T),
tabsetPanel(type="tabs",
tabPanel("tab1",
numericInput("Delete", "Delete row:", 1, step = 1),
actionButton("Go", "Delete!"),
verbatimTextOutput("df_data_files"),
verbatimTextOutput("values"),
verbatimTextOutput("rvTL"),
tableOutput("rvTL_out")
),
tabPanel("tab2",
tableOutput("df_data_out")
)
)))),
server = (function(input, output) {
values <- reactiveValues(df_data = NULL) ##reactiveValues
rvTL <- reactiveValues(rvTL = NULL)
observeEvent(input$file, {
values$df_data <- read.csv(input$file$datapath)
rvTL[[input$file$name]] <- c(isolate(rvTL), read.csv(input$file$datapath))
})
observeEvent(input$Go, {
temp <- values$df_data[-input$Delete, ]
values$df_data <- temp
})
output$df_data_files <- renderPrint(input$file$name)
output$values <- renderPrint(names(values))
output$rvTL <- renderPrint(names(reactiveValuesToList(rvTL))[1] )
output$rvTL_out <- renderTable(reactiveValuesToList(rvTL)[[1]])
output$df_data_out <- renderTable(values$df_data)
})
))
【问题讨论】: