Created
February 3, 2020 23:23
-
-
Save alandipert/89025cd9f57d7adbe95e35a25bd54039 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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() | |
}) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.