hafen / trelliscopejs

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

Error when using trelliscope in shiny app #18

Open hueanhpt opened 7 years ago

hueanhpt commented 7 years ago

Dear sir,

I tried to use trelliscopejs in shiny context but unfortunately the library was crashed. It displayed a blank frame with this text: Couldn't load config: http://127.0.0.1:4499/appfiles/config.jsonp?__loadTrscopeConfig__6aa8b26a=jsonp_z4meir93mfzis31

This snippet did work on RStudio(console + viewer)

 mpg %>%
        group_by(manufacturer, class) %>%
        summarise(panel = panel(
          qplot(cty, hwy) + xlab("cty") + ylab("hwy") +
            xlim(7, 37) + ylim(9, 47) + theme_bw()
        )) %>%
        trelliscope(name = "dplyr_gg")

My shiny app as below: ui.R

library(shiny)
shinyUI(fluidPage(
  trelliscopeOutput("plot")
))

server.R

library(shiny)
library(trelliscopejs)
library(dplyr)
library(ggplot2)

shinyServer(function(input, output) {
  output$plot <- renderTrelliscope({
    return(
      mpg %>%
        group_by(manufacturer, class) %>%
        summarise(panel = panel(
          qplot(cty, hwy) + xlab("cty") + ylab("hwy") +
            xlim(7, 37) + ylim(9, 47) + theme_bw()
        )) %>%
        trelliscope(name = "dplyr_gg")
    )
  })
})

My session info:

R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11 (El Capitan)

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

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

other attached packages:
[1] ggplot2_2.2.0       dplyr_0.5.0         trelliscopejs_0.1.3 shiny_0.14.2       

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.6             rstudioapi_0.6          knitr_1.15.1           
 [4] magrittr_1.5            devtools_1.12.0         progress_1.1.2         
 [7] munsell_0.4.3           colorspace_1.2-6        xtable_1.8-2           
[10] R6_2.2.0                plyr_1.8.4              tools_3.3.1            
[13] grid_3.3.1              gtable_0.2.0            DBI_0.5-1              
[16] withr_1.0.2             htmltools_0.3.5         yaml_2.1.14            
[19] lazyeval_0.2.0          assertthat_0.1          digest_0.6.10          
[22] tibble_1.1              tidyr_0.6.0             purrr_0.2.2            
[25] htmlwidgets_0.8         DistributionUtils_0.5-1 base64enc_0.1-3        
[28] memoise_1.0.0           mime_0.5                labeling_0.3           
[31] scales_0.4.1            prettyunits_1.0.2       jsonlite_1.1           
[34] httpuv_1.3.3           

How could I fix the problem ?

hafen commented 7 years ago

Thanks for the example. I'll take a look and hopefully it will be fairly easy to fix. There are so many contexts these can be used in (web, RStudio viewer, R Markdown, notebooks, Shiny, etc.) that it is difficult to rigorously test them all, and I haven't given enough attention to Shiny yet as I haven't had any personal use cases for it yet, but I will take a look.

hueanhpt commented 7 years ago

Thanks for your reply. I'm looking forward to receiving your feedback.

mrhopko commented 7 years ago

This is shaping up really well. Unfortunately I've been unable to create a working shiny example.

Do you have a working example I can attempt to replicate?

Kind regards.

kaneplusplus commented 7 years ago

I'm seeing this problem as well and I've been able to reproduce it in the example above. Also Darwin.

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib

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

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

other attached packages:
[1] ggplot2_2.2.1       dplyr_0.5.0         trelliscopejs_0.1.8
[4] shiny_1.0.3        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.10            knitr_1.15.1            magrittr_1.5           
 [4] progress_1.1.2          munsell_0.4.3           colorspace_1.3-2       
 [7] xtable_1.8-2            R6_2.2.0                plyr_1.8.4             
[10] tools_3.4.0             webshot_0.4.0           grid_3.4.0             
[13] gtable_0.2.0            DBI_0.6-1               htmltools_0.3.6        
[16] yaml_2.1.14             lazyeval_0.2.0          assertthat_0.2.0       
[19] digest_0.6.12           tibble_1.3.0            tidyr_0.6.1            
[22] purrr_0.2.2             htmlwidgets_0.8         DistributionUtils_0.5-1
[25] base64enc_0.1-3         mime_0.5                labeling_0.3           
[28] compiler_3.4.0          scales_0.4.1            prettyunits_1.0.2      
[31] jsonlite_1.4            httpuv_1.3.3           
iainmwallace commented 7 years ago

Awesome package - I am also getting the same error when I try to create a shiny app. FYI - my use case is to let a user upload a table that will then be plotted using Trelliscope.

hafen commented 7 years ago

Yes there is a strange htmlwidget sizing issue I'm experiencing with Shiny apps. Sorry for the delay on this. I'm out for a couple of weeks but will look into this as soon as I can.

statkclee commented 6 years ago

+1

blairj09 commented 6 years ago

+1

ghost commented 6 years ago

I managed to get this to work by including self_contained = TRUE in my trelliscope call

Ex. facet_trelliscope(~column, self_contained = TRUE)

clabornd commented 4 years ago

In my case this was due to the server not being allowed to guess the content type of the jsonp file when requesting the config. Adding the mapping jsonp = "application/javascript" to mimemap.R in mime appears to have solved it for me.