简体   繁体   中英

Creating multiple Data Frames in the same reactive function and outputting each separately

On the server side I take user inputted data:

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

Then I use this input to create multiple data frames in reactive statement:

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

Here's the issue --> I want to output both the dataframes df1 and df2 to the user but I cannot figure out the syntax to do so.I can try to output one data frame using the renderDataTable command (on the server side and linked to the UI side) but that doesn't work either.

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

I guess my problem is how do I tell the machine which data frame to grab in the output$bogus statement. Maybe I want df1, maybe I want df2, maybe both from the getdata reactive statement

You can use a list to return a pair of objects list(df1=..., df2=...) then use getdata()[['df1']]

But it's usually a good idea to have one dataset by reactive so this is what I would do:

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())

Also you could probably replace data[data[,1] %in% stressed.flag(),1:11] by data[data$col1Name==stressed.flag(),1:11]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM