r - 在 Shiny 中显示 dbplyr 收集进度

标签 r shiny dplyr dbplyr

我正在编写一个 Shiny 的仪表板。为了加载数据,我使用了等效的

    mydata <- reactive({
      in.positions <- isolate(input$positions)
      (db_conn
        %>% tbl('table1')
        %>% filter(position %in% in.positions)
        %>% inner_join(db_conn %>% tbl('table2'), by = 'id')
        %>% collect()
      )
   })

这里db_conn是一个dbPool对象。 问题是有时会有很多数据并且需要一些时间来加载它。 有什么方法可以监视 collect() 的进度,最好映射到 Shiny 的进度条吗?

最佳答案

我使用 shinycssloaders 起草了一个示例仪表板。要点是将您的 UI 元素通过管道传输到 withSpinner 函数中。希望这会有所帮助。

library(shiny)
library(shinycssloaders)
library(ggplot2)
library(magrittr)

ui <- fluidPage(  
  sidebarPanel(
    selectInput('n_datapoints', label = 'how many?',
                choices=c(1000, 10000, 1000000))
  ),

  mainPanel(
    plotOutput('plot') %>%
      # Adds a dark red spinner while waiting for the plot
      withSpinner(color='#8B0000')
  )
)

server <- function(input, output, session) {

  # Some long-running data retrieval
  data <- reactive({
    rnorm(input$n_datapoints)
  })

  # Get the plot
  output$plot <- renderPlot(
    data() %>% 
      plot()
  )
}

shinyApp(ui, server)

enter image description here

关于r - 在 Shiny 中显示 dbplyr 收集进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61855509/

相关文章:

r - 使用 dplyr 创建具有多个参数的函数

r - 不支持的索引类型 : list error when converting columns from factors to numerics

r - 如何在igraph中设置Louvain模块化的分辨率参数?

带保留评估的 RMOA Hoeffding 树

r 使用文件夹内容 Shiny 创建下拉菜单

r - 如何使用默认不折叠的 menuSubItem 部署 R Shinydashboard

r - 如何使用 Iframe 标记在 SharePoint 上嵌入 Shiny 的应用程序

r - 在 R magrittr 管道末尾使用 $ 美元符号返回向量

r - R data.table计算新列,但在开头插入

r - add_row 并做一些计算