Shiny - Storing Reactive data frame for every input updated by user

Hi Friends,
Please help with below.

As the value of input$Val changes the reactive grp_data() changes.
Is it possible to capture those changes in grp_data() and store them based on input$Val for comparison later.


library(shiny)
library(tidyverse)

m1<-rnorm(20,100,sd=20)
m2<-rnorm(20,120,sd=40)
m3<-rnorm(20,140,sd=60)

data<-data.frame(m1,m2,m3)

ui<-fluidPage(
   sliderInput('Val',"COV limit for X",min=0.3, max=0.8,value=0.5,step=0.1),
  tableOutput("table1")
  )

server<-function(input,output,session)
{

   grp_data <- reactive({
   
    t1<-data %>%
      rowwise() %>%
      mutate(COV_3M = sd(across(m1:m3))/rowMeans(across(m1:m3)),
             XYZ_3M = if_else(COV_3M < input$Val, "X","Y")) %>%
      group_by(XYZ_3M) %>%
       tally()
    
      })
  
    output$table1 <-renderTable( grp_data())
  }
shinyApp(ui=ui,server=server)

Think you are looking for eventReactive

Hi ,

Thanks for sharing event reactive wont solve it .

You just want the value of grp_data to change each time the input changes?

Hi when the value changes 3 or 4 times i want the data frame to change and importantly each data frame as reactive to be saved and available for future comparison

say for value of 0.3 is dataframe_0.3
for value of 0.5 is dataframe 0.5
for value of 0.8 is dataframe 0.8

Seems like you want Persistent data storage? See here: https://shiny.rstudio.com/articles/persistent-data-storage.html

Maybe try something like this (I am not on a computer so may have to experiment a bit/correct and definitely my coding knowledge is shaky at best )

GRP<- reactiveValues()

GRP$data<-list()

GRP$inputValue<-list()

counter<-reactiveValues()
counter$count<- 0

observeEvent( input$yourInput, {
counter$count=counter$count +1

GRP$data[[counter$count]]<-.code here

GRP$inputValue[[counter$count]]<- input$yourInput

})

Basically trying to make reactive lists via an observeEvent

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.