Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created February 3, 2020 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/89025cd9f57d7adbe95e35a25bd54039 to your computer and use it in GitHub Desktop.
Save alandipert/89025cd9f57d7adbe95e35a25bd54039 to your computer and use it in GitHub Desktop.
---
title: "Promises/Future Test"
runtime: shiny
output: html_document
---
```{r, include=FALSE}
library(promises)
library(future)
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
selectInput("input", label = "Select data", choices = c("iris", "mtcars"))
dat <- reactive({
if (input$input == "iris") iris else mtcars
})
# get_data <- function() {
# future({
# dat()[, c(2, 3)]
# })
# }
get_data <- future({
dat()[, c(2, 3)]
})
```
```{r, echo=FALSE}
renderPlot({
get_data %...>% plot()
})
```
@alandipert
Copy link
Author

When run, no plot appears and the following error is produced: 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.)

Changing the definition of get_data to the following resolves the problem.

get_data <- future({
    dat()[, c(2, 3)]
}, lazy = TRUE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment