Сократить время обратного вызова Leaflet R в блестящей - PullRequest
0 голосов
/ 31 марта 2020

Я работаю над блестящим приложением, которое использует удивительный пакет листовок.

Короче говоря: я провел анализ profvis приложения, и график довольно четко показывает, что большая часть времени расходуется на фаза обратного вызова (которая, я полагаю, не зависит от моего кодирования?).

Есть ли у вас какая-либо стратегия сокращения этого потерянного времени?

enter image description here

Вот код пользовательского интерфейса:

library(shiny)
library(shinycssloaders)

# Define UI for application that draws a histogram
navbarPage("Italy Covid", id="nav",
           tabPanel("Interactive Map", 
                    div(class = "outer",
                        tags$head(
                            # Include our custom CSS
                            includeCSS(here::here("ItalyCovidDashboard/styles.css"))
                        ),
                        leaflet::leafletOutput("map", height = "100%"),
                        absolutePanel(id = "controls", class = "panel panel-default", 
                                      fixed = TRUE, draggable = TRUE, top = 60, 
                                      left = "auto", right = 20, bottom = "auto",
                                      width = 330, height = "auto",
                                      h2("Italian Covid Data explorer"),
                                      dateInput("date", "Select the date for the data", Sys.Date() - 1, 
                                                min = as.Date("2020-02-24")),
                                      radioButtons("type", "Tyoe of data", choices = c("Region", "Province"),
                                                   selected = "Region"),
                                      conditionalPanel(condition = "input.type == 'Region'",
                                                       selectInput("field", "", 
                                                                   choices = c("Hospitalised", "In ICU", "Home Isolation",
                                                                               "Dead", "Healed", "Total"),
                                                                   selected = "Total"))
                        )
                    )
           )
)

Вот сервер один

shinyServer(function(input, output, session) {

    Data <- isolate(GetRawData()) # Loads Italian Covid19 data and Italy GADM data

    # Map Setup

    type <- reactive({input$type})
    field <- reactive({input$field})
    date <- reactive({input$date})

    ItalyMap <- reactive({FilterAndPrepareToPlot(Data, date(), type(), field())}) # Data wrangling

    output$map <- leaflet::renderLeaflet({
        leaflet::leaflet() %>% 
            leaflet::addProviderTiles("Esri.WorldTerrain") %>% 
            leaflet::setView(10, 41.879, zoom = 5)})

    observe({
        italy <- ItalyMap()
        #create a color palette to fill the polygons
        bin <- seq(0, max(italy$cases) + 1, length.out = 10)
        pal <- leaflet::colorBin("Reds", bins=bin)

        #create a pop up (onClick)
        polygon_popup <- paste0(paste0("<strong>",type(),": </strong>"), italy$name, 
                                "<br>", paste0("<strong>",field()," cases: </strong>"), 
                                italy$cases)
        leaflet::leafletProxy("map", data = italy, session) %>% 
            leaflet::clearShapes(.) %>% 
            leaflet::addPolygons(fillColor= ~pal(cases),
                                 fillOpacity = 0.4, 
                                 weight = 2, 
                                 color = "grey",
                                 popup = polygon_popup) 
    })



})

...