hafen / trelliscopejs

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

Generate an Index.html file in shiny with plotly? #119

Open David-Degnan opened 2 years ago

David-Degnan commented 2 years ago

Hello! We are building a shiny application that generates trelliscope displays. Due to security issues when we deploy the app, we must keep jsonp = FALSE. Plotly graphics only display when self_contained = FALSE; however, no Index.html file is generated. If we pipe it to the print function, the generated Index.html does not visualize correctly (no plots). We want to provide users the capability ot download a standalone trelliscope from the app (thus the need for the Index.html file). Is there a way to generate an Index.html file in shiny with plotly while keeping jsonp=FALSE?Thanks. I am on version 0.2.10. Below is some example code I was using:

library(shiny)
library(plotly)
library(dplyr)
library(tidyr)
library(trelliscopejs)

data("iris")

ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
          selectInput("xlab", "X Label", colnames(iris)[1:4], selected = colnames(iris)[1]),
          selectInput("ylab", "Y Label", colnames(iris)[1:4], selected = colnames(iris)[2]),
          textInput("theName", "Trelliscope Name", "name"),
          selectInput("selfcontained", "Self Contained?", c("TRUE", "FALSE"), "TRUE")
        ),
        mainPanel(
            trelliscopeOutput("TestTrelli")
        )
    )
)

server <- function(input, output, session) {

  output$TestTrelli <- renderTrelliscope({

    iris %>% 
      group_by(Species) %>%
      nest() %>%
      mutate(
        panel = map_plot(data, function(data) {
          plot_ly(x = data[[input$xlab]], y = data[[input$ylab]], type = "scatter", mode = "markers")
        })
      ) %>%
      ungroup() %>%
      trelliscope(path = "www/trelli", name = input$theName, self_contained = as.logical(input$selfcontained), jsonp = FALSE, thumb = TRUE)

  })

}

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