Twitter分析应用程序
我想创建一个基本的闪亮应用程序,在其中我可以在文本输入框中键入关键字,当我单击submit时,输出应该是在文本输入框中键入关键字的最近推文的数据表。我还需要找到一种方法,使用setup_twitter_oauth自动启用我的应用程序和twitter之间的握手。我已经创建了以下app.R文件 但当我运行代码运行应用程序时,出现以下错误: origname=name,shinysession=self中出现错误: 未使用的参数name=name,shinysession=self 警告:观察者中未处理的错误:客户端错误:400错误请求 observeEventinput$twitterTwitter分析应用程序,twitter,twitter-oauth,shiny,Twitter,Twitter Oauth,Shiny,我想创建一个基本的闪亮应用程序,在其中我可以在文本输入框中键入关键字,当我单击submit时,输出应该是在文本输入框中键入关键字的最近推文的数据表。我还需要找到一种方法,使用setup_twitter_oauth自动启用我的应用程序和twitter之间的握手。我已经创建了以下app.R文件 但当我运行代码运行应用程序时,出现以下错误: origname=name,shinysession=self中出现错误: 未使用的参数name=name,shinysession=self 警告:观察者中未处
只要searchTwitter返回df或矩阵,这项功能就会起作用。经过多次失败的实验后,以下代码成功了:
library(shiny)
ui <- fluidPage(
textInput("handle", "Search Tweets:"),
sliderInput("maxTweets","Number of recent tweets to use for analysis:",min=5,max=1500, value = 5),
downloadButton("download", "Download File"),
dataTableOutput("table")
)
server <- function(input, output) {
library(twitteR)
consumerKey = "My key"
consumerSecret = "My secret"
accessToken = "My token"
accessSecret = "My secret"
my_oauth <- setup_twitter_oauth(consumer_key = consumerKey, consumer_secret = consumerSecret,
access_token = accessToken, access_secret = accessSecret)
output$table <- renderDataTable({
TweetFrame<-function(searchTerm, maxTweets)
{
twtList<-searchTwitter(searchTerm,n=maxTweets)
twtList1<- do.call("rbind",lapply(twtList,as.data.frame))
twtList1$text<-iconv(twtList1$text, 'UTF-8', 'ASCII') #WILL THIS SOLVE THE UTF ENCODING PROBLEM: http://lists.hexdump.org/pipermail/twitter-users-hexdump.org/2013-May/000335.html
return(twtList1)
}
entity1<-reactive({entity1<-TweetFrame(input$handle, input$maxTweets)})
output$table <- renderDataTable({tab<-entity1()[1]})
output$download <- downloadHandler(filename = function() {paste(input$handle, '.csv', sep='')},
content = function(file){
write.csv(entity1(), file)
}
)
})
}
shinyApp(ui = ui, server = server)
尽管我仍然无法弄清楚如何在没有用户干预的情况下自动启用用户身份验证。在这方面的任何帮助都将不胜感激。请在回答中提及这一点,斯科特·张伯伦建议了一种替代方法来实现您的目标。我想你可以用上面提到的方法。
server <- function(input, output){
source(file = 'oauth.RData') #file containing the credentials
output$table <- renderDataTable({
test <- searchTwitter(input$twitter, n=1500)
return(test)
})
}
library(shiny)
ui <- fluidPage(
textInput("handle", "Search Tweets:"),
sliderInput("maxTweets","Number of recent tweets to use for analysis:",min=5,max=1500, value = 5),
downloadButton("download", "Download File"),
dataTableOutput("table")
)
server <- function(input, output) {
library(twitteR)
consumerKey = "My key"
consumerSecret = "My secret"
accessToken = "My token"
accessSecret = "My secret"
my_oauth <- setup_twitter_oauth(consumer_key = consumerKey, consumer_secret = consumerSecret,
access_token = accessToken, access_secret = accessSecret)
output$table <- renderDataTable({
TweetFrame<-function(searchTerm, maxTweets)
{
twtList<-searchTwitter(searchTerm,n=maxTweets)
twtList1<- do.call("rbind",lapply(twtList,as.data.frame))
twtList1$text<-iconv(twtList1$text, 'UTF-8', 'ASCII') #WILL THIS SOLVE THE UTF ENCODING PROBLEM: http://lists.hexdump.org/pipermail/twitter-users-hexdump.org/2013-May/000335.html
return(twtList1)
}
entity1<-reactive({entity1<-TweetFrame(input$handle, input$maxTweets)})
output$table <- renderDataTable({tab<-entity1()[1]})
output$download <- downloadHandler(filename = function() {paste(input$handle, '.csv', sep='')},
content = function(file){
write.csv(entity1(), file)
}
)
})
}
shinyApp(ui = ui, server = server)