Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
闪亮应用中的Twitter-输入文本挑战_R_Shiny - Fatal编程技术网

闪亮应用中的Twitter-输入文本挑战

闪亮应用中的Twitter-输入文本挑战,r,shiny,R,Shiny,我是新来的闪亮和R 但为了在尝试中学习,我尝试使用示例阅读twitterapi和shinny。但是,我无法使textIinput$text成为被动的,因此当用户在闪亮的应用程序中输入文本时,会生成output$distPlot 我试过这个 aga = reactive ({searchTwitter(input$text, n=3200, lang = "en")}) 但它从来都不起作用 我还检查了stackoverflow.com上的其他示例- 这是我的代码,我期待着您的帮助和建议 serv

我是新来的闪亮和R

但为了在尝试中学习,我尝试使用示例阅读twitterapi和shinny。但是,我无法使textIinput$text成为被动的,因此当用户在闪亮的应用程序中输入文本时,会生成output$distPlot

我试过这个

aga = reactive ({searchTwitter(input$text, n=3200, lang = "en")})
但它从来都不起作用

我还检查了stackoverflow.com上的其他示例-

这是我的代码,我期待着您的帮助和建议

server.R

library(shiny)
library(twitteR)
library(ROAuth)
library(dplyr)




# Define server logic required to draw a histogram
shinyServer(function(input, output) {

  ##Retrieve tweets from Twitter

  ## Twitter authentication
  #Connecting to Twitter
  consumer_key <- "xxx"
  consumer_secret <-"xxx"
  access_token <- "xxx"
  access_secret <- "xxx"
  setup_twitter_oauth(consumer_key, consumer_secret, access_token,
                      access_secret)

 **# this does not work**

  #aga = reactive ({searchTwitter(input$text, n=3200, lang = "en")}) 

**#this works**
  aga = searchTwitter("@bhp", n=3200, lang = "en") 


  # convert tweets to a data frame
  agadf <- twListToDF(aga) 


  agadf$created<-as.Date(agadf$created)




  #Sentiment Analysis
  require(devtools)
  #install_github("sentiment140", "okugami79", force= TRUE)
  library(sentiment)
  agasentiments <- sentiment(agadf$text)
  table(agasentiments$polarity)

  # sentiment plot
  agasentiments$score <- 0
  agasentiments$score[agasentiments$polarity == "positive"] <- 1
  agasentiments$score[agasentiments$polarity == "negative"] <- -1
  agasentiments$date <- as.Date(agadf$created)
  agaresult <- aggregate(score ~ date, data = agasentiments, sum)
  plot(agaresult, type = "l")


  output$distPlot <- renderPlot({
    plot(agaresult, type = "l")

  })

})
library(shiny)
library(twitteR)
library(ROAuth)
library(dplyr)

# Define UI for application that draws a histogram
shinyUI(fluidPage(

  # Application title
  titlePanel("Real Time Miner Sentiment"),

  # Sidebar with a slider input for number of bins 
  sidebarLayout(
    sidebarPanel(

        textInput("text", "Text:", "text here"),
        submitButton("Submit")
    ),

    # Show a plot of the generated distribution
    mainPanel(
       plotOutput("distPlot")
    )
  )
))

@zx8754-不知道您是否能提供帮助。我很难复制这个例子

您好-非常感谢您在这个问题上的帮助Hello-非常感谢您在这个问题上的帮助