hafen / trelliscopejs

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

trelliscope does not render in Shiny #37

Open brooklynbagel opened 7 years ago

brooklynbagel commented 7 years ago

Rendering a trelliscopejs plot through Shiny does not appear to work.Running the app on both Chrome and Firefox and inspecting the webpage reveal the following errors:

Error: only one instance of babel-polyfill is allowed

and

ReferenceError: trelliscopeApp is not defined

An example shiny app is below and attached is the code.

library(shiny)
library(rbokeh)
library(trelliscopejs)
library(tidyverse)

# Define UI for application
ui <- fluidPage(
  trelliscopeOutput('trelliscope')
)

# Define server logic
server <- function(input, output) {

  output$trelliscope <- renderTrelliscope({
    d <- mpg %>%
      group_by(manufacturer, class) %>%
      summarise(
        mean_city_mpg = mean(cty),
        mean_hwy_mpg = mean(hwy),
        panel = panel(
          figure(xlab = "City mpg", ylab = "Highway mpg",
                 xlim = c(7, 37), ylim = c(9, 47)) %>%
            ly_points(cty, hwy,
                      hover = data_frame(model = paste(year, model),
                                         cty = cty, hwy = hwy))))
    d %>%
      trelliscope(name = "city_vs_highway_mpg", nrow = 2, ncol = 4)
  })

}

# Run the application 
shinyApp(ui = ui, server = server)

My session info:

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.3

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] dplyr_0.5.0         purrr_0.2.2         readr_1.0.0         tidyr_0.6.1         tibble_1.2         
[6] ggplot2_2.2.1       tidyverse_1.1.1     trelliscopejs_0.1.8 rbokeh_0.5.0        shiny_1.0.0        

loaded via a namespace (and not attached):
[1] progress_1.1.2          gistr_0.3.6             reshape2_1.4.2          haven_1.0.0            
[5] lattice_0.20-34         colorspace_1.3-2        htmltools_0.3.5         yaml_2.1.14            
[9] base64enc_0.1-3         hexbin_1.27.1           foreign_0.8-67          DBI_0.5-1              
[13] pryr_0.1.2              modelr_0.1.0            readxl_0.1.1            plyr_1.8.4             
[17] stringr_1.2.0           munsell_0.4.3           gtable_0.2.0            rvest_0.3.2            
[21] htmlwidgets_0.8         codetools_0.2-15        psych_1.6.12            evaluate_0.10          
[25] labeling_0.3            knitr_1.15.1            forcats_0.2.0           httpuv_1.3.3           
[29] parallel_3.3.2          broom_0.4.2             Rcpp_0.12.9             xtable_1.8-2           
[33] scales_0.4.1            backports_1.0.5         DistributionUtils_0.5-1 webshot_0.4.0          
[37] jsonlite_1.3            mime_0.5                mnormt_1.5-5            hms_0.3                
[41] digest_0.6.12           stringi_1.1.2           grid_3.3.2              rprojroot_1.2          
[45] tools_3.3.2             magrittr_1.5            maps_3.1.1              lazyeval_0.2.0         
[49] xml2_1.1.1              prettyunits_1.0.2       lubridate_1.6.0         assertthat_0.1         
[53] rmarkdown_1.3           httr_1.2.1              R6_2.2.0                nlme_3.1-131         

The code and error logs from Chrome and Firefox trelliscope-shiny.zip in this example are attached in the zip file.

nauticalsmile commented 5 years ago

I thank the creator of this useful package for the time he put into it.

I also can confirm that I am unable to render Trelliscope in Shiny using the renderTrelliscope/outputTrelliscope binding functions as Brooklynbagel asked.

Any help or update would be most appreciated!

hafen commented 4 years ago

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")

Please give it a try and let me know if you have any issues.

PWPiranha commented 4 years ago

Hi. It has been wonderful to work with Trelliscope within RStudio. Wondering if recent updates cover some of the trellis applications with Shiny? I tried the following, but could not get it to work in Shiny. But a more basic ggplot2 version rendered properly.

library(shiny)
library(trelliscopejs)
library(ggplot2)
library(gapminder)

ui <- fluidPage(

  titlePanel("Facet with TrelliscopeJS"),
  mainPanel(
    trelliscopeOutput(outputId="trellis_facet", width = "100%", height = "400px")
  )
)
server <- function(input, output) {
  output$trellis_facet <- renderTrelliscope({
    qplot(year, lifeExp, data = gapminder) +
      theme_bw() +
      facet_trelliscope(~continent)
  })
}
shinyApp(ui = ui, server = server)

Basic ggplot2 version works:

library(shiny)
library(trelliscopejs)
library(ggplot2)
library(gapminder)

ui <- fluidPage(
   titlePanel("Facet with Basic ggplot"),
           mainPanel(
            plotOutput("ggplot")
        )
    )
server <- function(input, output) {
    output$ggplot <- renderPlot({
        qplot(year, lifeExp, data = gapminder) +
            theme_bw() +
            facet_wrap(~continent)
    })
}
shinyApp(ui = ui, server = server)