I am trying to get plotly working with the new async features in shiny. When running the example async app found on the @async branch the synchronous app loads just fine, but the async ones never do. Plotly was installed with devtools::install_github("ropensci/plotly@async")
library(shiny)
library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
library(ggplot2)
library(promises)
library(future)
plan(multisession)
ui <- fluidPage(
plotlyOutput("plot1"),
plotlyOutput("plot2"),
plotlyOutput("plot3")
# plotlyOutput("plot4")
)
server <- function(input, output, session) {
output$plot1 <- renderPlotly({
# Async plot_ly
future({ Sys.sleep(2); cars }) %...>%
plot_ly(x = ~speed, y = ~dist, type = "scatter", mode = "markers")
})
output$plot2 <- renderPlotly({
# Async ggplotly
future({ Sys.sleep(2); mtcars }) %...>%
{ ggplot(., aes(hp, mpg)) + geom_point() } %...>%
ggplotly()
})
output$plot3 <- renderPlotly({
# Not async
plot_ly(iris, x = ~Sepal.Length, y = ~Sepal.Width,
type = "scatter", mode = "markers")
})
# output$plot4 <- renderPlotly({
# # Ensure errors are handled properly (should be blank)
# future({}) %...>%
# { req(FALSE) }
# })
}
shinyApp(ui, server)
Try the master branch devtools::install_github("ropensci/plotly")
Seeing same issue on master branch / CRAN 4.8 - Only plot3 renders in a browser.
Boiled it down to a single reproducible example:
displays nothing in R Studio Viewer:
future({ Sys.sleep(2); mtcars }) %...>%
{ ggplot(., aes(hp, mpg)) + geom_point() } %...>%
ggplotly()
displays a plotly graph:
ggplotly(ggplot(mtcars, aes(hp, mpg)) + geom_point())`
Same issue: not working with
all other packages on latest cran version
Only the 3rd (sync) plot is shown. Error "Unhandled promise error"
Seems to work for me. Please report your devtools::session_info()
Session info -------------------------------------------------------------------------------------
setting value
version R version 3.5.1 (2018-07-02)
system x86_64, darwin15.6.0
ui RStudio (1.1.453)
language (EN)
collate en_US.UTF-8
tz America/New_York
date 2018-07-27
Packages -----------------------------------------------------------------------------------------
package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.5.0)
base * 3.5.1 2018-07-05 local
bindr 0.1.1 2018-03-13 CRAN (R 3.5.0)
bindrcpp * 0.2.2 2018-03-29 CRAN (R 3.5.0)
codetools 0.2-15 2016-10-05 CRAN (R 3.5.1)
colorspace 1.3-2 2016-12-14 CRAN (R 3.5.0)
compiler 3.5.1 2018-07-05 local
crayon 1.3.4 2017-09-16 CRAN (R 3.5.0)
crosstalk 1.0.0 2016-12-21 CRAN (R 3.5.0)
data.table 1.11.4 2018-05-27 CRAN (R 3.5.0)
datasets * 3.5.1 2018-07-05 local
devtools 1.13.6 2018-06-27 CRAN (R 3.5.0)
digest 0.6.15 2018-01-28 CRAN (R 3.5.0)
dplyr 0.7.6 2018-06-29 cran (@0.7.6)
future * 1.9.0 2018-07-23 CRAN (R 3.5.0)
ggplot2 * 3.0.0 2018-07-03 CRAN (R 3.5.0)
globals 0.12.1 2018-06-25 CRAN (R 3.5.0)
glue 1.3.0 2018-07-17 cran (@1.3.0)
graphics * 3.5.1 2018-07-05 local
grDevices * 3.5.1 2018-07-05 local
grid 3.5.1 2018-07-05 local
gtable 0.2.0 2016-02-26 CRAN (R 3.5.0)
htmltools 0.3.6 2017-04-28 CRAN (R 3.5.0)
htmlwidgets 1.2 2018-04-19 CRAN (R 3.5.0)
httpuv 1.4.5 2018-07-19 CRAN (R 3.5.0)
httr 1.3.1 2017-08-20 CRAN (R 3.5.0)
jsonlite 1.5 2017-06-01 CRAN (R 3.5.0)
labeling 0.3 2014-08-23 CRAN (R 3.5.0)
later 0.7.3 2018-06-08 CRAN (R 3.5.0)
lazyeval 0.2.1 2017-10-29 CRAN (R 3.5.0)
listenv 0.7.0 2018-01-21 CRAN (R 3.5.0)
magrittr 1.5 2014-11-22 CRAN (R 3.5.0)
memoise 1.1.0 2017-04-21 CRAN (R 3.5.0)
methods * 3.5.1 2018-07-05 local
mime 0.5 2016-07-07 CRAN (R 3.5.0)
munsell 0.5.0 2018-06-12 CRAN (R 3.5.0)
parallel 3.5.1 2018-07-05 local
pillar 1.3.0 2018-07-14 CRAN (R 3.5.0)
pkgconfig 2.0.1 2017-03-21 CRAN (R 3.5.0)
plotly * 4.8.0 2018-07-20 CRAN (R 3.5.0)
plyr 1.8.4 2016-06-08 CRAN (R 3.5.0)
promises * 1.0.1 2018-04-13 CRAN (R 3.5.0)
purrr 0.2.5 2018-05-29 CRAN (R 3.5.0)
R6 2.2.2 2017-06-17 CRAN (R 3.5.0)
Rcpp 0.12.18 2018-07-23 cran (@0.12.18)
rlang 0.2.1 2018-05-30 CRAN (R 3.5.0)
rstudioapi 0.7 2017-09-07 CRAN (R 3.5.0)
scales 0.5.0 2017-08-24 CRAN (R 3.5.0)
shiny * 1.1.0 2018-05-17 CRAN (R 3.5.0)
stats * 3.5.1 2018-07-05 local
tibble 1.4.2 2018-01-22 CRAN (R 3.5.0)
tidyr 0.8.1 2018-05-18 CRAN (R 3.5.0)
tidyselect 0.2.4 2018-02-26 CRAN (R 3.5.0)
tools 3.5.1 2018-07-05 local
utils * 3.5.1 2018-07-05 local
viridisLite 0.3.0 2018-02-01 CRAN (R 3.5.0)
withr 2.1.2 2018-03-15 CRAN (R 3.5.0)
xtable 1.8-2 2016-02-05 CRAN (R 3.5.0)
yaml 2.2.0 2018-07-25 CRAN (R 3.5.0)
(should note that this also didn't work prior to R 3.5.1 upgrade)
I had the same issue, and I know why examples don't work. Plotly for R is based on htmlwidgets, and CRAN version 1.2 doesn't support async yet. However, it works with latest htmlwidgets from git master
thanks kmatveev! Version 1.2.1 of htmlwidgets did the trick.
Most helpful comment
I had the same issue, and I know why examples don't work. Plotly for R is based on htmlwidgets, and CRAN version 1.2 doesn't support async yet. However, it works with latest htmlwidgets from git master