0

I am trying to pass a simple integer to a Shiny Flexdashboard. But I can for some reason only to it staticly, but I'd rather have it reactivly;

aggregated_static <- readRDS( "../rdsdata/aggregated_static.rds")
k <- nrow(aggregated_static)

That piece of code passes the number of rows to my Shiny dash, where it can be accessed with;

item_lines = k

But, if I do it this way, it won't work, telling me I can't access reactive content from that spot;

set_aggregated <- reactiveFileReader(1000, session,  "./rdsdata/set_aggregated.rds", readRDS)
k <- nrow(aggregated_static())

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.)

Now I've tried using Isolate, creating a function enclosing that with reactive({}), but I am simply nog getting that value passed. Is there a way to do this?

Eloque
  • 311
  • 2
  • 10
  • You can define k and used as `data <- reactivevalues(k=0)`; `data$k <-nrow(...)` – A. Suliman Jun 14 '18 at 11:33
  • Please provide a reproducible example, that will allow others to help you much better. See [How to make a Shiny app reproducible example?](https://stackoverflow.com/questions/48343080) for some tips on how to do so. – Florian Jun 15 '18 at 06:18

1 Answers1

0

If you want the value of k to be reactive, you should wrap it in reactive(), i.e.:

k <- reactive(nrow(aggregated_static()))

and then call its value as k()

Florian
  • 24,425
  • 4
  • 49
  • 80
  • I've tried the code provided, but that gives the same error `set_aggregated <- reactiveFileReader(1000, session, "./rdsdata/hub_set_aggregated.rds", readRDS)` and then `k <- reactive(nrow(set_aggregated()))` – Eloque Jun 14 '18 at 15:48
  • Is everything defined within your server function? If not, please see my comment on the question and provide a reproducible example and I'll have another look. – Florian Jun 15 '18 at 06:18