【问题标题】:Creating multiple Data Frames in the same reactive function and outputting each separately在同一个反应函数中创建多个数据帧并分别输出
【发布时间】:2017-06-21 06:11:36
【问题描述】:

在服务器端,我获取用户输入的数据:

stressed.flag <- reactive({input$flags})

然后我使用这个输入在响应式语句中创建多个数据框:

getdata <- reactive({
df <- readWorksheetFromFile(x, y)   
df1 <- df[which(df[,1] %in% stressed.flag()),1:11]
)}

这是问题——>我想将数据帧 df1 和 df2 都输出给用户,但我不知道这样做的语法。我可以尝试使用 renderDataTable 命令输出一个数据帧(在服务器端并链接到 UI 端),但这也不起作用。

  output$bogus = renderDataTable({
            df1()
        })

我想我的问题是如何告诉机器在 output$bogus 语句中抓取哪个数据帧。也许我想要 df1,也许我想要 df2,也许两者都来自 getdata 响应式语句

【问题讨论】:

    标签: dataframe shiny reactive


    【解决方案1】:

    您可以使用列表返回一对对象list(df1=..., df2=...),然后使用getdata()[['df1']]

    但是通过响应式拥有一个数据集通常是个好主意,所以我会这样做:

    stressed.flag <- reactive({input$flags})
    df <- reactive(readWorksheetFromFile(x, y)) 
    df1 <- reactive({ 
       data <- df();
       data[data[,1] %in% stressed.flag(),1:11]})
    output$full= renderDataTable(df())
    output$stressed= renderDataTable(df1())
    

    您也可以将data[data[,1] %in% stressed.flag(),1:11] 替换为data[data$col1Name==stressed.flag(),1:11]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 2018-08-20
      • 2022-08-12
      • 1970-01-01
      • 2022-08-06
      • 1970-01-01
      相关资源
      最近更新 更多