hafen / trelliscopejs

TrelliscopeJS R Package
https://hafen.github.io/trelliscopejs
Other
263 stars 37 forks source link

Trelliscope plots not displaying in RStudio viewer #19

Open ChrisMuir opened 7 years ago

ChrisMuir commented 7 years ago

Hello, I'm exploring the package and working through examples, I can't seem to get visualizations to appear in the viewer window of RStudio. I'm using this code as an example:

qplot(year, lifeExp, data = gapminder) + xlim(1948, 2011) + ylim(10, 95) + theme_bw() + facet_trelliscope(~ country + continent, nrow = 2, ncol = 7, width = 300, path = local_dir)

Specifying the "path" parameter will open the visualization within a new web browser window, but nothing I try will display it within the viewer plane. Opening the web inspector of RStudio and drilling down on script file trelliscopejs_widget.js, the graves accent character is labeled as invalid (see attached image).

I don't know if this is causing the viewer plane issue or not, but I thought I'd pass it along.

Thanks for all the hard work on this package, I've found it very useful.

invalid_char_trelliscopejs_widget

Here's my session info: R version 3.2.3 (2015-12-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252

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

other attached packages: [1] dplyr_0.5.0 readr_1.0.0 UpSetR_1.3.1 shiny_0.14.2 shinydashboard_0.5.3 trelliscopejs_0.1.4 ggplot2_2.2.1
[8] rbokeh_0.5.0 housingData_0.3.0 gapminder_0.2.0

loaded via a namespace (and not attached): [1] Rcpp_0.12.8 pryr_0.1.2 plyr_1.8.4 prettyunits_1.0.2 base64enc_0.1-3 tools_3.2.3
[7] progress_1.1.2 digest_0.6.10 memoise_1.0.0 jsonlite_1.2 evaluate_0.10 tibble_1.2
[13] gtable_0.2.0 lattice_0.20-33 DBI_0.5-1 curl_2.3 yaml_2.1.14 hexbin_1.27.1
[19] gridExtra_2.2.1 withr_1.0.2 httr_1.2.1 stringr_1.1.0 knitr_1.15.1 devtools_1.12.0
[25] htmlwidgets_0.8 DistributionUtils_0.5-1 maps_3.1.1 rprojroot_1.1 grid_3.2.3 R6_2.2.0
[31] rmarkdown_1.3 tidyr_0.6.0 purrr_0.2.2 gistr_0.3.6 magrittr_1.5 backports_1.0.4
[37] scales_0.4.1 codetools_0.2-14 htmltools_0.3.5 assertthat_0.1 xtable_1.8-2 mime_0.5
[43] colorspace_1.3-2 httpuv_1.3.3 labeling_0.3 stringi_1.1.2 lazyeval_0.2.0 munsell_0.4.3

hafen commented 7 years ago

Thanks for the report. I just noticed this the other day on a Windows VM but wasn't sure if it was a one-off because of my setup or something. It looks like this must be a Windows-specific issue because plots show up in the viewer on my mac. I'll look into it. Quick question - how were you able to open the RStudio web inspector for a trelliscope display if the display didn't show up in the RStudio viewer? Just asking because that might help me troubleshoot.

ChrisMuir commented 7 years ago

Hi hafen. To answer you question, here are the steps I took to get that screen shot:

  1. Run the qplot + facet_trelliscope sample code in RStudio.
  2. Right click anywhere within RStudio, select "Inspect" from the drop down menu (which brings up the web inspector in a separate window).
  3. Select "Resources" within web inspector window.
  4. Select Frames > 127.0.0.1/ > index.html > Scripts > trelliscopejs_widget.js

If there's anything else I can do to help please don't hesitate to ask, thanks.

Edit to add: Also, I just read through all the comments in your original blog post about this pkg and I see there was some discussion related to this issue. If I do NOT specify path within the call to facet_trelliscope, the viewer pane is empty but clicking on "Show in new window" will open the plot in a web browser window, as mentioned by poster "ImAndy" here: http://ryanhafen.com/blog/trelliscopejs#comment-3009783890

hafen commented 7 years ago

Thanks. I may make it default to never try to output to the RStudio viewer because it's usually much too cramped for Trelliscope displays. The only downside to this is that then you don't get the "publish" button if you want to publish to RStudio Connect.

I wasn't able to get the the console error through your steps, but through a different test I was doing with an R Markdown document on Windows, I saw the same issue. I fixed the backtick template literals (a feature of modern browsers but apparently not available in this case) in my widget binding but still came across more errors:

screen shot 2017-01-04 at 3 10 17 pm

Object.assign() is another feature of more modern browsers that trelliscopejs-lib uses. I looked at "Help -> About RStudio":

screen shot 2017-01-04 at 3 10 39 pm

The user agent string seems to indicate WebKit versions corresponding with Safari 8 which doesn't have these features available.

So to support this, I would need to put in polyfills which could cause some issues. I need to investigate further.

ChrisMuir commented 7 years ago

Thanks for looking into it and for your work on the package. Again, if there's anything I can do to help or you if want more info from me please don't hesitate to ask.

hafen commented 7 years ago

Oh yeah I forgot to hop on here to let you know that I updated the JS library with polyfills to work on older browsers. I figured this would be a good thing to do anyway - the more that can view, the merrier. So after installing the latest, you shouldn't see any console errors anymore and displays will show up in the RStudio browser for R Markdown documents and such on Windows. However, plots still won't print to the viewer, which I can't figure out. If you can try the latest and can find any more clues (maybe your console log will show something I'm not seeing), that would be appreciated!

ChrisMuir commented 7 years ago

So with the updates, as you mentioned it's still not printing the plot to the RStudio viewer. However the SyntaxError related to the backtick marks is now gone, and there are zero warnings/errors within the web inspector. Here's a screen shot:

rstudio_screenshot_2

Some other things that are different from my last web inspector screen shot, within index.html I now have "Fonts" and "Images", the images are files of all of the plots that are supposed to be on page one of the trelliscope (my code dictated eight panels per page). And under Scripts, I now have the jsonp file of each of the eight panels that go on page one (I'm plotting country data, hence "Belgium", "Denmark", etc.).

Within htmlwidgets.js, I can see two points that make reference to the viewer pane, at "var viewerMode" and within "function sizingPolicy(el)". I'm afraid I don't know js well enough to unpack and troubleshoot further than that.

If you think there's anything else I can do to help please let me know. Good luck to you.

abd-ul-Basit commented 4 years ago

Hello. I just discovered this wonderful library. Though I am having trouble viewing the Trelliscope graphs in the in the RStudio Viewer Pane or in the Shiny. I am using the same code snippet as above:

qplot(year, lifeExp, data = gapminder) + xlim(1948, 2011) + ylim(10, 95) + theme_bw() + facet_trelliscope(~ country + continent, nrow = 2, ncol = 7, width = 300, path = local_dir)

Could you kindly tell me what might be the issue.

hafen commented 4 years ago

It shows up in the RStudio viewer for me:

Screen Shot 2019-11-12 at 3 15 58 PM

R 3.6.1 RStudio 1.2.1335 trelliscopejs 0.1.18 MacOS 10.14.6

Also, for embedding in Shiny, I recently updated the package to work more nicely with Shiny. These changes are located in the dev branch, which you can install with

remotes::install_github("hafen/trelliscopejs@dev")

There are several other updates in this version, so please let me know if you run into any other issues.

abd-ul-Basit commented 4 years ago

Nopes. Installed Library from your method above and still doesn't view in either the Viewer Pane or my Shiny App. My RStudio Version is 1.2.5001 with 3.6.1 as my R version, trelliscopejs 0.1.18 and Windows 10.

Maybe it might be an issue with R running on Windows !

Hope you resolve this soon.

Am doing everything manually now !

Best Of Luck

hafen commented 4 years ago

Not sure about RStudio viewer, but Shiny should work regardless of OS.

Can you try running this simple app with the dev version of trelliscopejs

https://gist.github.com/hafen/ef69d752b08cb1fe005461e55bde24b4

and let me know if that works?

As for the viewer pane, I can't replicate your setup so I don't know how to fix it. If someone else with a similar setup wants to investigate, that would be great. Otherwise, I don't see it as a major issue as I've stated before that the viewer pane isn't ideal for viewing trelliscope outputs since it's so cramped.

FelipeCarrillo commented 2 years ago

Was this issue ever resolved? I am having the same problem. I want to be able to display trelliscope plots on my Rstudio device but the plots are displaying on a separate window. Is this the normal behavior? I am using RStudio 2021.09.1 Build 372 and R 3.6.3.