How to save the value of an output to use it in another output?

I am calculating something to present it as a table output. But when I try to download, I discovered that I have to calculate everything again to get the same set of data that I am presenting. How I can avoid this?

Beforehand, thank you very much

Hi, welcome!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one for a shiny app

Hi @andresrcs

Background information
I have this interface

Considerations:
Initially the report tab is empty.

Process Flow:

  1. When you select what you want to filter, including the variable slider, then
    you press the "Apply Filters" button and then below of the title "Detail of dataset" will appear a renderTable() with the filtered dataset.
    Also, It'll appear a "Run Analysis" button.
    This execution is using this¬
    output$table1 <- DT::renderDataTable(DT::datatable({

         result <- dataset
    
         if (input$filter_1 != "Todo"){
               result <- result[result$value1 == input$filter_1,]
         }
         if (input$filter_2 != "Todo") {
               result <- result[result$value2 == input$filter_2,]
         }
         if (input$filter_3 != "Todo") {
               result <- result[result$value3 == input$filter_3,]
         }
        result
    
       result
    

}))
2. When you press the "Run Analysis" button. It will take the filtered dataset and procede to run something else.
This execution is using this ¬
observeEvent(input$Run, {
output$table2 <- renderTable({
here I run my analysis and I put the result dataset at the end
})
})

  1. Finally, the table with the result will appear in the "Report" tab and also a "Download .csv" using the following code in the ui component ¬
    tabPanel(
    title = 'Report',
    value = "tab2",
    tableOutput('table2'),
    downloadButton("downloadData", "Download (.csv)")
    )

Inconvenient:
When I tried to write my code to download the final report. I realized that I needed to run the analysis again to get the dataset and then be able to download it.

Other issues:
I also realized that I have to run the filtering code to reproduce the same filtered dataset to run my main analysis

Could you please read the guide I gave you before and turn this into a proper self contained reproducible example?

In the meanwhile you can consider creating the dataframe globally for each session in your server function, that way you can reference it from any reactive function and you wouldn't have to filter again.

Hi,

I am pretty sure the answer I received from PJ can help you with this!

Regards,

Maxime

1 Like

Thank you @Maxime_deb, I'm gonna check it right now.

Excelent @Maxime_deb. That's exactly what I needed

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.