Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLWidgets and xmlSVG not rendering #20

Closed
osker130 opened this issue Mar 26, 2019 · 14 comments
Closed

HTMLWidgets and xmlSVG not rendering #20

osker130 opened this issue Mar 26, 2019 · 14 comments

Comments

@osker130
Copy link

Hello,

I love the potential of this package. However, I notice that many of the examples are not rendering in the official readme: https://metrumresearchgroup.github.io/slickR/. I ran the code on my own machine and reproduced the problem. Any ideas?

J

@yonicd
Copy link
Owner

yonicd commented Mar 26, 2019

Thank you for pointing that out. I didnt notice that those examples broke.

@yonicd
Copy link
Owner

yonicd commented Mar 27, 2019

can you paste the sessioninfo::session_info() into the issue.

I can render the sliders in the rstudio IDE the plots, there seems to be a problem with the standalone output for the xmlSVG and how it is rendered in the browser (in my case chrome).

@osker130
Copy link
Author

I tried to run with regular plots and a ggplot. Neither one renders.

library(svglite)
library(ggplot2)
library(dplyr)
library(slickR)

plotsToSVG=list(
  #Standard Plot
  xmlSVG({plot(1:10)},standalone=TRUE),
  #ggplot
  xmlSVG({show(ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,colour=Species))+
                 geom_point())},standalone=TRUE) 
)

#make the plot self contained SVG to pass into slickR 
s.in=sapply(plotsToSVG,function(sv){paste0("data:image/svg+xml;utf8,",as.character(sv))})

slickR(s.in,slideId = 'ex4',slickOpts = list(dots=T), height = 200,width = '100%')`
sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] gdtools_0.1.7 slickR_0.2.4  dplyr_0.7.8   ggplot2_3.1.0 svglite_1.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1       rstudioapi_0.9.0 xml2_1.2.0       bindr_0.1.1     
 [5] magrittr_1.5     tidyselect_0.2.5 munsell_0.5.0    cowplot_0.9.4   
 [9] colorspace_1.4-0 R6_2.4.0         rlang_0.3.1      plyr_1.8.4      
[13] tools_3.5.2      grid_3.5.2       gtable_0.2.0     withr_2.1.2     
[17] htmltools_0.3.6  digest_0.6.18    yaml_2.2.0       lazyeval_0.2.1  
[21] assertthat_0.2.0 tibble_2.0.1     crayon_1.3.4     bindrcpp_0.2.2  
[25] purrr_0.2.5      base64enc_0.1-3  htmlwidgets_1.3  glue_1.3.0      
[29] labeling_0.3     compiler_3.5.2   pillar_1.3.1     scales_1.0.0    
[33] jsonlite_1.6     pkgconfig_2.0.2 

@yonicd
Copy link
Owner

yonicd commented Mar 27, 2019

Hi

You are running slickr v0.2.4, can you update to the GH master (slickR v0.4) and try again please.

remotes::install_github('metrumresearchgroup/slickR')

Thanks

@yonicd yonicd closed this as completed Mar 27, 2019
@yonicd yonicd reopened this Mar 27, 2019
@yonicd
Copy link
Owner

yonicd commented Mar 27, 2019

Also what browser/version are you using to open the rendered file on?

I see that there is a problem on

  • chrome 75.0.3745.4 (Official Build) dev (64-bit)
  • firefox 6.0.1 (64-bit)

but not on

  • safari 12.0.3 (14606.4.5)

@yonicd
Copy link
Owner

yonicd commented Mar 27, 2019

cc @timelyportfolio @lionel- any ideas why the standalone svg+xml from {svglite} would be having problems on those browsers?

@lionel-
Copy link

lionel- commented Mar 27, 2019

Are the SVGs included inline? We had problems with inline SVGs in vdiffr before this fix: r-lib/vdiffr#51

I'm not knowledgeable in the matter unfortunately.

@yonicd
Copy link
Owner

yonicd commented Mar 27, 2019

Yes they are inline. thanks for the link

@yonicd
Copy link
Owner

yonicd commented Mar 27, 2019

@osker130 this should work for you. I'll update the html link that is with the package.

library(svglite)
library(ggplot2)
library(slickR)

plotsToSVG=list(
  #Standard Plot
  xmlSVG({plot(1:10)},standalone=TRUE),
  #ggplot
  xmlSVG({show(ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,colour=Species))+
                 geom_point())},standalone=TRUE) 
)

hash_encode_url <- function(url){
  gsub("#", "%23", url)
}

#make the plot self contained SVG to pass into slickR 
s.in=sapply(plotsToSVG,function(sv){
  hash_encode_url(paste0("data:image/svg+xml;utf8,",as.character(sv)))
  })

slickR(s.in,slideId = 'ex4',slickOpts = list(dots=T), height = 200,width = '100%')

@osker130
Copy link
Author

@yonicd @lionel- thank you both! @yonicd your solution works well. The svgs now render fine. Any thoughts on the HTML widgets? I tried the slickR v0.4 update yesterday when I was having problems and then reverted after concluding that the update wasn't the solution. My goal is to use these in an Rshiny application. Most users will be accessing with google chrome as their default browser.

@yonicd
Copy link
Owner

yonicd commented Mar 27, 2019

which html widget didn't work? i have those examples working on my side.

@osker130
Copy link
Author

This one wont render in RStudio. I'm left with grey boxes for leaflet and white boxes for plottly. The widgets work fine as standalones.

suppressMessages({
  library(leaflet)
  library(plotly)
})

l <- leaflet() %>% addTiles()
htmlwidgets::saveWidget(l,'leaflet.html')

p <- iris%>%ggplot(aes(x=Sepal.Length,y=Sepal.Width))+geom_point()
pL= ggplotly(p)
htmlwidgets::saveWidget(pL,'ggplotly.html')

slickR(c(rep(paste0(readLines('leaflet.html'),collapse='\n'),4),
         rep(paste0(readLines('ggplotly.html'),collapse='\n'),4)),
       slideId = c('leaf','plot'),
       slideIdx = list(1:4,5:8),
       slideType = rep('iframe',2),
       slickOpts = list(list(dots=T,slidesToShow=2,slidesToScroll=2),
                        list(dots=T,slidesToShow=2,slidesToScroll=2)),
       height='400px',width='100%')

@yonicd
Copy link
Owner

yonicd commented Mar 28, 2019

It’s a known problem that Iframes don’t in render in the rstudio viewer, only in the browser

@yonicd yonicd closed this as completed Aug 28, 2019
@osker130
Copy link
Author

osker130 commented Aug 28, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants