How I can change dynamically the frequency of data in r/shiny?

172 Views Asked by At

Hi an thanks for reading me. I am currently working on a small app that displays a simple time series chart, but I would like it to dynamically change the aggregation of the data. I'm trying the Tidyquant function, but it's giving me an error message. Do you know if there is a solution to this or some other way to do it?

The code is the following:

library(tidyquant)
library(echarsts4r)
library(shiny)
library(dplyr)
library(lubridate)

info <- data.frame(
  date = seq.Date(from = as.Date('1998-09-15'), to = as.Date('1999-11-15'), by = 1),
  value = sample(400:500, size = 427, replace = TRUE)
)




shinyApp(
  ui = fluidPage(
    column(width = 4,
           selectInput("xd","agregado",
                       choices = c("apply.daily","apply.weekly", "apply.monthly")
                       )
           ),
    column(width = 8, echarts4rOutput("grafico")  )
  ),
  
  server = function(input, output){
    
    output$grafico <- renderEcharts4r({
      
      x <- .data[[input$xd]]
      
      info |> 
        tq_transmute(select     = value,
                     mutate_fun = x,
                     FUN        = sum) |> 
        e_charts(date) |> 
        e_line(loc, symbol = "none") |> 
        e_theme("auritus") |> 
        e_tooltip(trigger = "axis") |> 
        e_title("Avg driver sharing location", left = "center") |> 
        e_legend(FALSE)
      
      
    })
  }
)

Specifically, the problem is inside the function renderEcharts4r({}), with the following lines:

x <- .data[[input$xd]]


info |> 
   tq_transmute(select = value,
                mutate_fun = x,
                FUN =      sum)

I can't get the function to add the data dynamically (weekly, monthly, etc)

0

There are 0 best solutions below