Reactive values not working

One more question, trying to implement this solution on a shiny app, for some reason it´s not working there, using reactivevalues this way

values <- reactiveValues(mydata = NULL,myplot=NULL)
      values$mydata %>%
        mutate(TotArtFillRate_Sem4 = ITRec_4/ITOrd_4) %>% 
        mutate(TotArtFillRate_Sem3 = ITRec_3/ITOrd_3) %>% 
        mutate(TotArtFillRate_Sem2 = ITRec_2/ITOrd_2) %>% 
        mutate(TotArtFillRate_Sem1 = ITRec_1/ITOrd_1) %>% 
        mutate(TotArtSum4Wks = TotArtFillRate_Sem4+TotArtFillRate_Sem3+TotArtFillRate_Sem2+TotArtFillRate_Sem1) %>% 
        mutate(CedisTiendaFillRate_Sem4 = STRec_4/STOrd_4) %>% 
        mutate(CedisTiendaFillRate_Sem3 = STRec_3/STOrd_3) %>% 
        mutate(CedisTiendaFillRate_Sem2 = STRec_2/STOrd_2) %>% 
        mutate(CedisTiendaFillRate_Sem1 = STRec_1/STOrd_1) %>% 
        mutate(CedisTiendaSum4Wks = CedisTiendaFillRate_Sem4+CedisTiendaFillRate_Sem3+CedisTiendaFillRate_Sem2+CedisTiendaFillRate_Sem1) %>% 
        mutate(PrecioProm_Sem4 = Vta_04/Ventas_04) %>% 
        mutate(PrecioProm_Sem3 = Vta_03/Ventas_03) %>% 
        mutate(PrecioProm_Sem2 = Vta_02/Ventas_02)%>% 
        mutate(PrecioProm_Sem1 = Vta_01/Ventas_01)%>% 
        mutate(PrecioProm_Sum4Wks = PrecioProm_Sem4+PrecioProm_Sem3+PrecioProm_Sem2+PrecioProm_Sem1)%>% 
        mutate(PrecioPromLY_Sem4 = AAVta_04/AAVentas_04) %>% 
        mutate(PrecioPromLY_Sem3 = AAVta_03/AAVentas_03) %>% 
        mutate(PrecioPromLY_Sem2 = AAVta_02/AAVentas_02)%>% 
        mutate(PrecioPromLY_Sem1 = AAVta_01/AAVentas_01)%>% 
        mutate(PrecioPromLY_Sum4Wks = PrecioPromLY_Sem4+PrecioPromLY_Sem3+PrecioPromLY_Sem2+PrecioPromLY_Sem1)%>% 
        mutate(VarPrecio_Sem4 = PrecioProm_Sem4/PrecioPromLY_Sem4) %>% 
        mutate(VarPrecio_Sem3 = PrecioProm_Sem3/PrecioPromLY_Sem3) %>% 
        mutate(VarPrecio_Sem2 = PrecioProm_Sem2/PrecioPromLY_Sem2)%>% 
        mutate(VarPrecio_Sem1 = PrecioProm_Sem1/PrecioPromLY_Sem1)%>% 
      mutate(VarPrecio_Sum4Wks = PrecioProm_Sum4Wks/PrecioPromLY_Sum4Wks)

at the end it doesnt throw errors but it wont add those columns.
thanks a lot

If you want the changes to persist, then you have to assign them to the original variable e.g.

values$mydata <- values$mydata %>%
  mutate(TotArtFillRate_Sem4 = ITRec_4/ITOrd_4,
         TotArtFillRate_Sem3 = ITRec_3/ITOrd_3,
         TotArtFillRate_Sem2 = ITRec_2/ITOrd_2)

And BTW there is no need to call mutate() so many times, you can do it with just one.

If you need more specific help, please make a minimal REPRoducible EXample (reprex) of your app, here is a nice guie about making a reprex for a shiny app.

1 Like

thanks a lot will try it out really appreciate it

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.