推特分析 Shiny App
Twitter analysis Shiny App
我想创建一个基本的闪亮应用程序,其中我可以在文本输入框中键入关键字,当我单击提交时,输出应该是最近推文中输入关键字的数据 table文本输入框。我还需要找到一种方法,使用 setup_twitter_oauth
自动启用我的应用程序和 Twitter 之间的握手。我创建了以下 app.R
文件
library(shiny)
library(twitteR)
ui <- fluidPage(
titlePanel("Basic Twitter Search App"),
textInput("twitter", "Search Keyword"),
actionButton("click", label = "Search Tweets"),
dataTableOutput("table")
)
server <- function(input, output){
source(file = 'oauth.RData') #file containing the credentials
output$table <- renderDataTable
(
{
observeEvent(input$twitter, {searchTwitter(input$twitter, n=1500)
})
})
}
shinyApp(ui = ui, server = server)
但是当我运行代码(运行应用程序)时,出现以下错误:
Error in orig(name = name, shinysession = self) :
unused arguments (name = name, shinysession = self)
Warning: Unhandled error in observer: client error: (400) Bad Request
observeEvent(input$twitter)
server <- function(input, output){
source(file = 'oauth.RData') #file containing the credentials
output$table <- renderDataTable({
test <- searchTwitter(input$twitter, n=1500)
return(test)
})
}
只要 searchTwitter returns df 或矩阵
这应该有效
谢谢@Jimbo。经过多次失败的实验,以下代码起作用了:
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)
虽然我还没有弄清楚如何自动启用用户身份验证(无需用户干预)。在这方面的任何帮助将不胜感激。
我想创建一个基本的闪亮应用程序,其中我可以在文本输入框中键入关键字,当我单击提交时,输出应该是最近推文中输入关键字的数据 table文本输入框。我还需要找到一种方法,使用 setup_twitter_oauth
自动启用我的应用程序和 Twitter 之间的握手。我创建了以下 app.R
文件
library(shiny)
library(twitteR)
ui <- fluidPage(
titlePanel("Basic Twitter Search App"),
textInput("twitter", "Search Keyword"),
actionButton("click", label = "Search Tweets"),
dataTableOutput("table")
)
server <- function(input, output){
source(file = 'oauth.RData') #file containing the credentials
output$table <- renderDataTable
(
{
observeEvent(input$twitter, {searchTwitter(input$twitter, n=1500)
})
})
}
shinyApp(ui = ui, server = server)
但是当我运行代码(运行应用程序)时,出现以下错误:
Error in orig(name = name, shinysession = self) : unused arguments (name = name, shinysession = self) Warning: Unhandled error in observer: client error: (400) Bad Request observeEvent(input$twitter)
server <- function(input, output){
source(file = 'oauth.RData') #file containing the credentials
output$table <- renderDataTable({
test <- searchTwitter(input$twitter, n=1500)
return(test)
})
}
只要 searchTwitter returns df 或矩阵
这应该有效谢谢@Jimbo。经过多次失败的实验,以下代码起作用了:
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)
虽然我还没有弄清楚如何自动启用用户身份验证(无需用户干预)。在这方面的任何帮助将不胜感激。