Rendering brilliant rendering Serialization (interactive map)

I am doing an interactive treemap in Shiny for my professor. The treemap has at its worst 3 levels and 20,000 leaves. I'm having trouble getting this done within a reasonable time frame.

The number of interesting requests is quite small, so I created highcharter plot objects and serialized them beforehand:

library(readr)
library(magrittr)
library(highcharter)
library(treemap)

tm_file_name <- function(num_leaves) {
  paste0(as.character(num_leaves), "_leaves.rds")
}

create_rand_treemap <- function(num_leaves) {
  random.hierarchical.data(n = num_leaves) %>%
    treemap(index = c("index1", "index2", "index3"),
            vSize = "x",
            draw = FALSE) %>%
    hctreemap(allowDrillDown = TRUE) %>%
    write_rds(tm_file_name(num_leaves))
}

for (leaves in c(50, 500, 5000)) {
  create_rand_treemap(leaves)
}

      

My shiny app.r

file looks like this

library(shiny)
library(shinydashboard)
library(readr)
library(magrittr)
library(highcharter)

tm_file_name <- function(num_leaves) paste0(as.character(num_leaves), "_leaves.rds")
load_treemap <- function(num_leaves) tm_file_name(num_leaves) %>% read_rds()

ui <- dashboardPage(
  dashboardHeader(title = "Reproducible Interactive Highcharter Treemap Test",
                  titleWidth = "100%"),

  dashboardSidebar(
    div(style = "display:inline-block;width:100%;text-align:center;",
        radioButtons("num_leaves", "Number of Leaves in Treemap:",
                     c("50" = 50, "500" = 500, "5000" = 5000)),
        actionButton("createTreemap", "Create Treemap"))),

  dashboardBody(highchartOutput("treemap", width = "100%", height = "500px")),
)

# loads and renders plot object only on button press
server <- function(input, output) {
  output$treemap <- renderHighchart({
    if (length(input$createTreemap) != 0) {
      if (input$createTreemap > 0) isolate({load_treemap(input$num_leaves)})
    }
  })
}

shinyApp(ui = ui, server = server)

      

This brilliant live streaming app is here . Rendering times for treemaps with 50 and 500 leaves are approximately within the acceptable range. However, for 5000 leaves this is too slow and I need a final solution that can deal with up to 20,000 leaves.

Is there anything I can do to speed up the speed?

+3


source to share





All Articles