如何首先在屏幕上加载前两三个图表,然后在我的闪亮应用程序上加载其他图表

How to load first two or three charts first on screen while others later on my shiny application

提问人:akshay bholee 提问时间:8/25/2022 更新时间:8/25/2022 访问量:46

问:

我想在我闪亮的应用程序中首先在屏幕上加载前两三个图表。这是我闪亮的应用程序的链接: https://iecprojects.shinyapps.io/CountryProfile/

我加载前两三个图表的原因是我的应用程序需要 8 秒钟才能加载所有图表。

这是我的主要 UI 和服务器代码。每个模块都在渲染一个盒子。

#Libraries
source("global/libraries.R")

#### call modules #####
list.files("modules") %>% purrr::map(~ source(paste0("modules/", .)))
#### call modules #####


#### Connect to Production database #####
source("global/DBconnect.R")
#### End Connect to database #####


#### Initialize global dataframe ####
source("global/dataframe.R")
#### End Initialize global dataframe ####

#### Initialize global functions#### 
source("functions/functions.R")
#### End Initialize global functions ####



#### Create User Interface #####
ui <-
  tagList(  shinyjs::useShinyjs(),
    tags$head(# the javascript is checking the screen resolution to adapt the display
      tags$script(src = "javascripts.js")),
    tags$style(HTML(
      paste(
        "html,",
        ".container{
                    width: 100%;
                    margin: 0 auto;
                    padding: 0;
                }
               @media screen and (min-width: 700px){
                .container{
                    min-width: 1850px;
                    max-width: 1920px;
                }
               }
                          ",
        sep = " "
      )
    )),
    tags$div(
      class = "container",
      dashboardPage(
        dashboardHeader(disable = TRUE),
        dashboardSidebar(disable = TRUE),
        dashboardBody(
          
          tags$head(
            tags$link(rel = "stylesheet", type = "text/css", href = "styles.css")
          ),
          #UI for Country
          reporter_download_ui(id = "reporterdownload"),
          #End of UI for Country
          
          #UI for Demographics
          demographics_ui(id = "demographics"),
          #End of UI for Demographics

          #UI for Trade in goods
          tradeingoods_ui(id = "tradeingoods"),
          #End of UI for Trade in goods

          #UI for Trade Performance
          trade_performance_ui(id = "tradeperformance"),
          # #End of UI Trade Performance
          # 
          # #UI for Logistic Performance
           LPI_ui(id = "LPI"),
          # #End of UI Logistic Performance
          # 
          # #UI for Bilateral Trade
          bilateral_ui(id = "bilateral"),
          #End of UI Bilateral Trade

          #UI for Trade Agreements
          trade_agreement_ui(id = "agreement"),
          #End of UI Trade Agreements

          #UI for Trade in services
          tradeinservices_ui(id = "tradeinservices"),
          #End of UI Trade in services

          #UI for Services Performance
          servicesperformance_ui(id = 'servicesperformance'),
          #End of UI Services Performance

          #UI for Macroeconomic
          Macroeconomic_ui(id = "Macroeconomic"),
          #End of UI Macroeconomic

          #UI for Digital
          Digital_ui(id = "Digital"),
          #End of UI Digital

          #UI for Digital
          trade_facilitation_ui(id = "tradefacilitation")
          #End of UI Digital
          
        )
      )
    )
  )
#### End Create User Interface #####


#### Create Server actions #####
server <- shinyServer(function(input, output, session) {

  #Initialize color palette
  mycolor <- color_palette(id = "color")
  
  #Initialize reporter
  reporter_iso_sel <-
    reporter_download_server(id = "reporterdownload")
  
  #Initialize trade flow parameter
  tradeflow <- tradeflow_server(id = "tradeingoods")

  #Initialize Services trade flow parameter
  services_tradeflow <- Services_tradeflow_server(id = "tradeinservices")

  #### Demographics ####
  demographics_server(id = "demographics",
                      reporter_iso_sel = reporter_iso_sel$reporter_iso_sel)
  #### Demographics ####

  #### Trade in goods ####
  tradeingoods_server(
    id = "tradeingoods",
    reporter_iso_sel = reporter_iso_sel$reporter_iso_sel,
    reporter = reporter_iso_sel$reporter,
    mycolor = mycolor,
    tradeflow = tradeflow
  )
  #### Trade in goods ####

  #### Trade performance ####
  trade_performance_server(
    id = "tradeperformance",
    reporter_iso_sel = reporter_iso_sel$reporter_iso_sel,
    reporter = reporter_iso_sel$reporter,
    mycolor = mycolor
  )
  #### Trade performance ####

  #### Logistic performance ####
  LPI_server(
    id = "LPI",
    reporter_iso_sel = reporter_iso_sel$reporter_iso_sel,
    reporter = reporter_iso_sel$reporter,
    mycolor = mycolor
  )
  #### Logistic performance ####

  #### Bilateral Trade ####
  bilateral_server(
    id = "bilateral",
    reporter_iso_sel = reporter_iso_sel$reporter_iso_sel,
    reporter = reporter_iso_sel$reporter,
    mycolor = mycolor,
    tradeflow = tradeflow
  )
  #### Bilateral Trade ####

  #### Trade Agreements ####
  trade_agreement_server(
    id = "agreement",
    reporter_iso_sel = reporter_iso_sel$reporter_iso_sel
  )
  # #### Trade Agreements ####

  #### Trade in services ####
  tradeinservices_server(
     id = "tradeinservices",
     reporter_iso_sel = reporter_iso_sel$reporter_iso_sel,
     reporter = reporter_iso_sel$reporter,
     mycolor = mycolor,
     services_tradeflow = services_tradeflow
   )
  #### Trade in services ####

  #### Services performance ####
  services_performance_server(
    id = "servicesperformance",
    reporter_iso_sel = reporter_iso_sel$reporter_iso_sel,
    reporter = reporter_iso_sel$reporter,
    mycolor = mycolor
  )
  #### Services performance ####

  #### Macroeconomic ####
  Macroeconomic_server(
    id = "Macroeconomic",
    reporter_iso_sel = reporter_iso_sel$reporter_iso_sel,
    reporter = reporter_iso_sel$reporter,
    mycolor = mycolor
  )
  #### Macroeconomic ####

  #### Digital ####
  Digital_server(
    id = "Digital",
    reporter_iso_sel = reporter_iso_sel$reporter_iso_sel,
    reporter = reporter_iso_sel$reporter,
    mycolor = mycolor
  )

  trade_facilitation_server(
    id = "tradefacilitation",
    reporter_iso_sel = reporter_iso_sel$reporter_iso_sel,
    reporter = reporter_iso_sel$reporter,
    mycolor = mycolor
  )
  #### Digital ####
  
  #### Download ####
  # source("server/server_download.R")
  #### Download ####
  
})
#### End create Server actions #####

#### Run application #####
shinyApp(ui, server)
#### End Run application #####
R 性能 闪亮

评论

0赞 manro 8/25/2022
看这里: stackoverflow.com/questions/20490619/...
0赞 akshay bholee 8/26/2022
不,解决方案不起作用。它仍然在等待所有情节渲染,然后它将显示在屏幕上。我想先显示一些,然后再显示其他的。

答: 暂无答案