vegalite icon indicating copy to clipboard operation
vegalite copied to clipboard

vegalite doesn't render in the "Viewer" pane in RStudio when using remote files

Open cbailiss opened this issue 8 years ago • 7 comments

This is perhaps an unusual item to report as an issue, but please bear with me.

vegalite often(**) fails to render anything in the "Viewer" pane in RStudio, it is completely blank - on Windows at least, with the problem seen on multiple different systems using different Windows OS versions, including my home PC, all using RStudio 1.0.136. (**it was "often" for me, until I identified the cause).

For example, the following (taken from the vegalite docn) renders nothing in RStudio. Interestingly, clicking the "Show In New Window" button in the "Viewer" pane opens the view in a new web browser window where the chart is rendered OK.

library(vegalite) vegalite() %>% cell_size(500, 300) %>% add_data("https://vega.github.io/vega-editor/app/data/unemployment-across-industries.json") %>% encode_x("date", "temporal") %>% encode_y("count", "quantitative", aggregate="sum") %>% encode_color("series", "nominal") %>% scale_color_nominal(range="category20b") %>% timeunit_x("yearmonth") %>% scale_x_time(nice="month") %>% axis_x(axisWidth=0, format="%Y", labelAngle=0) %>% mark_area(interpolate="basis", stack="center")

Downloading the data file and changing the add_data() reference to the local copy of the file resolves the problem. This suggests quite strongly the problem is security permissions (likely in the embedded web browser control RStudio uses for the "Viewer" pane).

This is strictly speaking not an issue with vegalite but given the popularity of RStudio, I thought I'd report it here. A sensible way of dealing with this might be to add a few notes to the documentation to highlight the issue and the workarounds (i.e. click "Show In New Window" or avoid using remote files). This would avoid other people having similar frustration in RStudio with vegalite when the problem is not actually vegalite at all.

cbailiss avatar Feb 15 '17 18:02 cbailiss

Hrm. Pulling in @kevinushey to see if he can spare a sec for an opine.

This also reminds me I have to do a screen recording of complex ggplot2 plots still failing to plot to the in-pane rstudio graphics device on occasion

hrbrmstr avatar Feb 15 '17 18:02 hrbrmstr

Is this from the CRAN version or the current master branch here?

I have also run into this issue and I believe it's possible I introduced it when I updated vegalite.js, but that is not on CRAN yet. I'd love to confirm that this is my fault as it would at least help track it down. It's super annoying to me as well, but admittedly, I don't know enough to resolve the issue.

Note, I have also had this problem with local data frames in an RMarkdown document, although the remote-v-local solution you mentioned suggests it may be related to how curl or similar dependencies were built with RStudio. I'm also curious if it's related to #19.

jsonbecker avatar Feb 15 '17 18:02 jsonbecker

This was from the CRAN version. Given the "Viewer" pane in RStudio is an instance of the local web browser embedded into the application, I was wondering if a browser security setting might be the cause, e.g. preventing requests to a different domain, since the "Viewer" page is served from a local web server* and the remote data file request is to a completely different domain and browsers sometimes block that type of action. Pure speculation though.
All I know for certain is swapping from the remote URL-to-local path resolved the problem. *When you click "Show In A New Window" the URL is http://localhost...... EDIT: The fact it works when the "Viewer" page is opened in a full web browser window suggests it might not be browser security settings, since I guess the same restriction would apply there (unless the embedded browser is running under tighter restrictions).

cbailiss avatar Feb 15 '17 18:02 cbailiss

FWIW this appears to work in the development version of RStudio with the development version of vegalite (I tested on a Windows VM with RStudio v1.1.70) so this may have been a bug only recently fixed on the RStudio side.

Can you try downloading a daily build from http://dailies.rstudio.com and check whether things work on your end?

I did see some errors in the JavaScript console -- not sure if they're relevant here...

screen shot 2017-02-15 at 11 07 57 am

kevinushey avatar Feb 15 '17 19:02 kevinushey

Hi there I've just downloaded and installed a daily build, v1.1.76. The problem is still present. Changing the add_data() URL from a remote URL to a local file still resolves the problem.

cbailiss avatar Feb 17 '17 07:02 cbailiss

I have also re-tested after reinstalling vegalite from github. Same results as above.

cbailiss avatar Feb 17 '17 08:02 cbailiss

i am also running into a similar problem when kniting to PDF.

Some test code is here: https://gist.github.com/RobinL/0333ef61b6f5040247614297662c7dff

What's odd is it's only the first output read from a remote source that doesn't render.

In the code above, output 1 renders fine (since I load the remote json using jsonlite)

Output 2 does not render.

Then output 3 and 4 render fine.

Session info:

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X El Capitan 10.11.3

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] jsonlite_1.3   rjson_0.2.15   vegalite_0.7.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.9        base64_2.0         digest_0.6.12      rprojroot_1.2      backports_1.0.5    magrittr_1.5       evaluate_0.10      stringi_1.1.2     
 [9] curl_2.3           rmarkdown_1.3      webshot_0.4.0.9000 tools_3.3.2        stringr_1.2.0      htmlwidgets_0.8    rsconnect_0.5      yaml_2.1.14       
[17] clipr_0.3.2        htmltools_0.3.5    openssl_0.9.5      knitr_1.15.1  

I installed vegalite using devtools::install_github.

p.s. love the package, thanks for your work

RobinL avatar Mar 18 '17 09:03 RobinL