Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Blank Output and Shiny Warnings from Plotly in RStudio

I just installed Ubuntu 16.04, and I’m using RStudio Version 1.0.136.

I installed the latest version of plotly from the CRAN mirrors, but was starting to get the following error on some relatively simple scatter plots that had worked fine before I updated Ubuntu, RStudio, and plotly (Ubuntu was 14.04, I’m not sure what my previous version of plotly or RStudio were, I installed them sometime in summer 2016).

Error: Variables must be length 1 or 251.
Problem variables: 'y'

I Googled it, and found some threads that said it was a bug in plotly that wasn’t present in the version available on GitHub. I installed this version, but this didn’t resolve the problem. In fact, it’s made it worse. I still get that error in my original code, but in addition I often get a series of warnings, and plots (with or without warnings) appear blank in the viewer. Below is an example of a simple situation that reproduces the warnings.

> plot_ly(x=1:10, y=1:10, type="scatter", mode="markers")
There were 39 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: replacing previous import by ‘shiny::includeHTML’ when loading ‘crosstalk’
2: replacing previous import by ‘shiny::knit_print.shiny.tag’ when loading ‘crosstalk’
3: replacing previous import by ‘shiny::code’ when loading ‘crosstalk’
4: replacing previous import by ‘shiny::includeScript’ when loading ‘crosstalk’
5: replacing previous import by ‘shiny::includeMarkdown’ when loading ‘crosstalk’
6: replacing previous import by ‘shiny::tags’ when loading ‘crosstalk’
7: replacing previous import by ‘shiny::is.singleton’ when loading ‘crosstalk’
8: replacing previous import by ‘shiny::withTags’ when loading ‘crosstalk’
9: replacing previous import by ‘shiny::img’ when loading ‘crosstalk’
10: replacing previous import by ‘shiny::tagAppendAttributes’ when loading ‘crosstalk’
11: replacing previous import by ‘shiny::knit_print.shiny.tag.list’ when loading ‘crosstalk’
12: replacing previous import by ‘shiny::knit_print.html’ when loading ‘crosstalk’
13: replacing previous import by ‘shiny::tagAppendChild’ when loading ‘crosstalk’
14: replacing previous import by ‘shiny::includeCSS’ when loading ‘crosstalk’
15: replacing previous import by ‘shiny::br’ when loading ‘crosstalk’
16: replacing previous import by ‘shiny::singleton’ when loading ‘crosstalk’
17: replacing previous import by ‘shiny::span’ when loading ‘crosstalk’
18: replacing previous import by ‘shiny::a’ when loading ‘crosstalk’
19: replacing previous import by ‘shiny::tagList’ when loading ‘crosstalk’
20: replacing previous import by ‘shiny::strong’ when loading ‘crosstalk’
21: replacing previous import by ‘shiny::tag’ when loading ‘crosstalk’
22: replacing previous import by ‘shiny::p’ when loading ‘crosstalk’
23: replacing previous import by ‘shiny::validateCssUnit’ when loading ‘crosstalk’
24: replacing previous import by ‘shiny::HTML’ when loading ‘crosstalk’
25: replacing previous import by ‘shiny::h1’ when loading ‘crosstalk’
26: replacing previous import by ‘shiny::h2’ when loading ‘crosstalk’
27: replacing previous import by ‘shiny::h3’ when loading ‘crosstalk’
28: replacing previous import by ‘shiny::h4’ when loading ‘crosstalk’
29: replacing previous import by ‘shiny::h5’ when loading ‘crosstalk’
30: replacing previous import by ‘shiny::h6’ when loading ‘crosstalk’
31: replacing previous import by ‘shiny::tagAppendChildren’ when loading ‘crosstalk’
32: replacing previous import by ‘shiny::em’ when loading ‘crosstalk’
33: replacing previous import by ‘shiny::div’ when loading ‘crosstalk’
34: replacing previous import by ‘shiny::pre’ when loading ‘crosstalk’
35: replacing previous import by ‘shiny::htmlTemplate’ when loading ‘crosstalk’
36: replacing previous import by ‘shiny::suppressDependencies’ when loading ‘crosstalk’
37: replacing previous import by ‘shiny::tagSetChildren’ when loading ‘crosstalk’
38: replacing previous import by ‘shiny::includeText’ when loading ‘crosstalk’
39: replacing previous import by ‘shiny::hr’ when loading ‘crosstalk’

The original error doesn’t appear above, but I still get it when I run the code I was running before. Another interesting problem comes when I don’t get warnings, but the plot appears completely blank in the RStudio viewer. The below code produces that problem.

add_trace(plot_ly(x=1:10, y=1:10, type="scatter", mode="markers"), x=2:11, y=2:11)

Is anybody else aware of this problem and whether if it’s possible for me to resolve?

This works for me:

library(plotly)
p <- plot_ly(x=~1:10, y=~1:10, type=“scatter”, mode=“markers”) %>%
add_trace(x=1:10, y=2:11)
print §

I do encounter the blank viewer problem now and then. To further troubleshoot it, could you right click on the viewer, click on Inspect element and then on Console? When the viewer is blank, it should show an error there. Maybe that error can help you further solve the problem.