R Shiny渲染准备就绪后立即进行异步绘制

时间:2019-03-12 00:29:55

标签: r shiny

从下面的代码块中,可以异步/完全独立于plotlyOutput(“ apps”)渲染plotlyOutput(“ users”)吗?现在,我必须等待它们都完成所有过程,以将最终的闪亮应用渲染为单个整体输出。理想情况下,所有视觉效果都具有“ withSpinner”加载图标并独立加载。

我查看了future / promises,尝试用future({code})包装renderPlotly语句,但是无法正常工作,最终不确定那是否是正确的路径。

注意:df“ rsc_usage”是从S3-中的.feather文件加载的-我省略了该代码

### PULL IN REQUIRED LIBRARIES
library(shiny)
library(ggplot2)
library(plotly)
library(data.table)
library(dplyr)
library(aws.s3)
library(DT)
library(shinydashboard)
library(shinyWidgets)
library(tidyr)
library(feather)
library(shinycssloaders)


ui = dashboardPage(
  dashboardHeader(
    disable = FALSE,
    title = "Customer Activity",
    titleWidth = '100%'
  ),

  dashboardSidebar(disable = TRUE),
  dashboardBody(tabsetPanel(type = "tabs",
                            tabPanel(
                              'Analytics',
                              fluidRow(
                                column(6, plotlyOutput("users") %>% withSpinner(color = "#0dc5c1")),
                                column(6, plotlyOutput("apps") %>% withSpinner(color =
                                                                                 "#0dc5c1"))
                              )
                            )))
)


server <- function(input, output, session) {
  output$users <- renderPlotly({
    ggplotly(
      rsc_usage <- rsc_usage %>%
        group_by(username) %>%
        summarise(visits = n()) %>%
        arrange(desc(visits)) %>%
        head(15) %>%
        ggplot(., aes(
          reorder(username, visits),
          visits,
          text = sprintf("username: %s<br>visits: %s", username, visits)
        )) +
        geom_bar(stat = "identity") +
        coord_flip() +
        theme_minimal() +
        labs(y = "Number of page visits",
             x = NULL) +
        ggtitle("top users")
      ,
      tooltip = c("text")
    )
  })

  output$apps <- renderPlotly({
    ggplotly(
      rsc_usage <- rsc_usage %>%
        group_by(name) %>%
        summarise(visits = n()) %>%
        arrange(desc(visits)) %>%
        head(15) %>%
        ggplot(., aes(
          reorder(name, visits),
          visits,
          text = sprintf("name: %s<br>visits: %s", name, visits)
        )) +
        geom_bar(stat = "identity") +
        coord_flip() +
        theme_minimal() +
        labs(y = "Number of page visits",
             x = NULL) +
        ggtitle("top content")
      ,
      tooltip = c("text")
    )
  })

}

shinyApp(ui, server)

0 个答案:

没有答案