在下载推文时显示Shiny中的弹出窗口

时间:2018-01-27 09:46:20

标签: r shiny

我将以下函数存储在名为" functions_S.R"

的文件中
connect_twittR_api <- function() {

  library(twitteR)

  consumer_key <- my_key
  consumer_secret <- my_secret_key
  access_token <-  my_access_token
  access_secret <-  my_access_token

  setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)

}

功能

scrape_tweets <- function(){

  N=10  # tweets to request from each query
  S=200  # radius in miles

  lats=c(38.9,40.7, 37.8)
  lons=c(-77,-74, -122)
  cities=c("Alabama","Alaska", "Arizona")

  donald_temp <- searchTwitter('Donald+Trump',
                               lang="en",n=N,resultType="recent",

  geocode=paste(lats[1],lons[1],paste0(S,"mi"),sep=","))
  print(paste0("Scraping tweets for: ", cities[1]))

  df_total <- create_dataset(donald_temp, cities[1])

  for(i in 2:length(lons)){

    print(paste0("Scraping tweets for: ", cities[i]))
    donald_temp <- searchTwitter('Donald+Trump',
                            lang="en",n=N,resultType="recent",
                            geocode=paste(lats[i],lons[i],paste0(S,"mi"),sep=","))

    df_temp <- create_dataset(donald_temp, cities[i])
    df_total <- rbind(df_total, df_temp)
  }

return(df_total)
}

所以跑步:

connect_twittR_apI()
scrape_tweets()

给我一​​份来自各州唐纳德特朗普的推文清单:&#34;阿拉巴马州&#34;,&#34;阿拉斯加&#34;,&#34;亚利桑那州&#34;。这一切都有效,但我希望将其包含在Shiny应用程序中 - 由按钮触发。

所以骨架看起来像这样:

library(shiny)
setwd("")
source("functions_S.R")


UI <- fluidPage(
  actionButton("button", "An action button")
)
Server <- function(input, output) {

  observeEvent(input$button, {
    connect_twittR_api()
    tweets <- scrape_tweets()
  })

}


shinyApp(ui = UI, server = Server)

现在来自函数的粘贴元素:

 print(paste0("Scraping tweets for: ", cities[1]))

在后台运行。我想有一个弹出屏幕显示粘贴消息的进度条。关于我应该如何实现这一点的任何想法?

0 个答案:

没有答案