Operation not allowed without an active reactive context


#1

Hi, I'm sure this is a minor error, but cannot get my app working.

I understand that when creating a reactive data.frame we need to call it in the next lines of code as a function. I'm doing that but getting errors as shown next:

When using in my server.R file:

ecommerce()$fecha <- anydate(ecommerce$fecha, asUTC = FALSE, useR = FALSE)

I'm getting:



Listening on http://127.0.0.1:3641
Warning: Error in $: objeto de tipo 'closure' no es subconjunto
  49: inherits
  48: anydate
  47: server [/home/ogonzales/Escritorio/linioapp/server.R#43]
Error in ecommerce$fecha : objeto de tipo 'closure' no es subconjunto

On the other hand:

When using:

ecommerce$fecha <- anydate(ecommerce()$fecha, asUTC = FALSE, useR = FALSE)

Or:

  ecommerce()$fecha <- anydate(ecommerce()$fecha, asUTC = FALSE, useR = FALSE)

I'm getting:

Listening on http://127.0.0.1:3641
Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
  53: stop
  52: .getReactiveEnvironment()$currentContext
  51: .dependents$register
  50: ecommerce
  47: server [/home/ogonzales/Escritorio/linioapp/server.R#43]
Error in .getReactiveEnvironment()$currentContext() : 
  Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

this is my full server.R file. I would hope someone can look at it.

library(shiny)
library(ggplot2)
library(forcats)
library(scales)
library(plotly)
library(repmis) #loads data from DropBox
library(anytime)
library(dplyr)




### Data alojada en DropBox


ecommerce <- reactive({source_data("https://www.dropbox.com/s/vde35nfjhybfvr7/ecommerce.csv?raw=1")})




server <- function(input, output) {
 
  
  
  ecommerce()$fecha <- anydate(ecommerce()$fecha, asUTC = FALSE, useR = FALSE)
  

    
}

#2

Hi @o_gonzales,

the reactive you are calling should be executed inside a reactive expression or observer, just like the error message says.
I don't know what you want to do with your data, but assume you want to show it in a table, then you can call the reactive in the render method of the table. The table also needs to be defined in your ui.R btw.

output$table <- renderDataTable({
        df <- ecommerce()
        df$fecha <- anydate(df$fecha, asUTC = FALSE, useR = FALSE)
        df
})