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

renderTrelliscope() doesn't work in shinyapps.io #121

Open
Ebj8 opened this issue Aug 26, 2022 · 1 comment
Open

renderTrelliscope() doesn't work in shinyapps.io #121

Ebj8 opened this issue Aug 26, 2022 · 1 comment

Comments

@Ebj8
Copy link

Ebj8 commented Aug 26, 2022

I have a basic shiny app using the gapminder data set. It works just fine when I render it locally, but when I host the app on shinyapps.io it gives me the following error:
Couldn't load config: https://ebj8.shinyapps.io/Gapminder/_w_b0eb2e0d/trelliscopes/appfiles/config.jsonp?__loadTrscopeConfig__a177f523=jsonp_e4tdyzdgtas7oje

The logs have been largely unhelpful as hitting the "Render Trelliscope" button in my app doesn't appear to trigger anything in the logs.

Here is my app script:

library(shiny)
library(trelliscopejs)
library(gapminder)
library(ggplot2)
library(dplyr)
library(tidyr)

# This loads the gapminder dataset into 'dat'
dat <- gapminder |>
  filter(continent == "Europe")

ui <- fluidPage(
  titlePanel("Gapminder"),
  sidebarLayout(
    sidebarPanel(
      h3("Customize your trelliscope"),
      selectInput(inputId = "x_axis",
                  label = "x-axis variable",
                  choices = colnames(dat),
                  selected = "year"),
      selectInput(inputId = "y_axis",
                  label = "y-axis variable",
                  choices = colnames(dat),
                  selected = "lifeExp"),
      actionButton(inputId = "create_trelliscope",
                   label = "Render Trelliscope")
    ),
    mainPanel(
      # This function tells shiny where to put the trelliscope and how big to
      # make it
      trelliscopeOutput(outputId = "trelliscope", width = "80%", height = "1000px")
    )
  )
)

server <- function(input, output) {
  
  output$trelliscope <- renderTrelliscope({
    # The function below will be used for making plots in our trelliscope
    # Note: x represents a dataset that will be passed in
    scatter_plot = function(x) {
      ggplot(x, aes_string(input$x_axis, input$y_axis)) +
        geom_point() +
        theme_bw()
    }
    
    dat |>
      group_by(country) |>
      nest() |>
      mutate(
        # Use the scatter_plot function above to make a plot for each row of this
        # nested data set
        plots = map_plot(data, scatter_plot)
      ) |>
      ungroup() |>
      trelliscope(name = "Gapminder", nrow = 2, ncol = 4, path = "www/trelliscopes ")
  }) |>
    bindCache(input$x_axis, input$y_axis) |>
    bindEvent(input$create_trelliscope)
  
}

shinyApp(ui = ui, server = server)

And the app itself on shinyapps.io can be found at https://ebj8.shinyapps.io/Gapminder/

@SJokubauskaite
Copy link

SJokubauskaite commented Sep 7, 2022

Hi,

just change:
trelliscope(name = "Gapminder", nrow = 2, ncol = 4, path = "www/trelliscopes ")

into:
trelliscope(name = "Gapminder", nrow = 2, ncol = 4, path = "www/trelliscopes" , self_contained = TRUE)

Sadly this solution seems not to work with objects created with ggplotly.

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

2 participants