Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Trelliscope with Shiny

Tags:

r

rendering

shiny

I know that this question has been asked before, but so far has not been answered. If there is someone who could point to a working solution (any example is fine) pls share with me. I am regularly checking on the web (since 1 year) but so far notbody has solved the "trelliscope render shiny" problem. The code below should work, but in shiny only the title appears, no error message on the plot. Your help is highly appreciated! Best Alex

library(shiny)
library(ggplot2)
install.packages("gapminder")
library(gapminder)
devtools::install_github("hafen/trelliscopejs")
library(trelliscopejs)
ui <- fluidPage(

  # App title ----
  titlePanel("Hello trelliscope in Shiny!"),

  # Sidebar layout with input and output definitions ----
  fluidPage(

    # Main panel for displaying outputs ----
    mainPanel(

      # Output: Histogram ----
      trelliscopeOutput("plot", width = "100%", height = "400px")

    )
  )
)


server <- function(input, output) {

  output$plot <- renderTrelliscope(
    qplot(year, lifeExp, data = gapminder) +
      xlim(1948, 2011) + ylim(10, 95) + theme_bw() +
      facet_trelliscope(~ country + continent,
                        nrow = 2, ncol = 7, width = 300, as_plotly = TRUE)

    )
  }

shinyApp(ui, server)

1 Answers

Finally I´ve been able to get a working solution with some limitations though. I´ve created an app within RStudio: File -> New File -> Shiny Web App. In the app folder it seems that you have to create a "www" directory and set self_contained = TRUE. The below example works on my Mac.

library(trelliscopejs)
library(dplyr)
library(ggplot2)
library(tidyverse)


ui <- shinyUI(fluidPage(
  trelliscopeOutput(outputId = "plot")
))


server <- shinyServer(function(input, output) {
  output$plot <- renderTrelliscope({

    ggplot2::mpg %>%
      group_by(manufacturer, class) %>%
      nest() %>%
      mutate(
        panel = map_plot(data, ~
                           ggplot(data = ., aes(x = cty, y = hwy)) +
                           geom_point(color = I("red")) +
                           theme_bw())) %>%
      trelliscope(name = "output", self_contained = TRUE)
  })
})


shinyApp(ui = ui, server = server)```


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!