I am building a web app that downloads tweets using the 'twitteR' R package, munging those tweets and displaying them via a 'shiny' R web app. I have no problem executing the code that downloads and processes the tweets into a data frame:
do.call('rbind', lapply(userTimeline('nutwition_log'), as.data.frame))
... you can run this in your terminal (with the twitteR library loaded) yourself and see that it downloads the tweet data and prints the resulting data frame to the screen.
But, when I use this sort of call in a 'shiny' app (server-side)... for example...
server.R:
library(shiny)
library(twitteR)
shinyServer(function(input, output) {
datasetInput <- reactive(function() {
tweets <- userTimeline(input$subscriber)
do.call('rbind', lapply(tweets, as.data.frame))
})
output$view <- reactiveTable(function() {
head(datasetInput(), n = input$obs)
})
})
ui.R:
library(shiny)
library(twitteR)
shinyUI(pageWithSidebar(
headerPanel('FitnessTrack'),
sidebarPanel(
selectInput("subscriber", "Select Subscriber:",
choices = c("nutwition_log", "anotherAccount")),
numericInput("obs", "Number of observations to view:", 10)
),
mainPanel(
tableOutput("view")
)
))
... I get the following error:
Error in as.data.frame.default(X[[1L]], ...) :
cannot coerce class 'structure("status", package = "twitteR")' into a data.frame
Error in as.data.frame.default(X[[1L]], ...) :
cannot coerce class 'structure("status", package = "twitteR")' into a data.frame
Error in as.data.frame.default(X[[1L]], ...) :
cannot coerce class 'structure("status", package = "twitteR")' into a data.frame
... all I want to do is be able to change the user whose tweets are being downloaded and munged, then output the resulting data frame (... the datasetInput()
return, loaded to output$view
) to the mainPanel()
. I have no idea why this is not working.
Any help would be great!
I think I've got it: https://github.com/rstudio/shiny/commit/0b469f09df7e2ca3bbdb2ddadc8473a8126a9431
Until this is properly tested and rolled into a new Shiny build, you can test it by using devtools to install straight from GitHub:
library(devtools)
install_github('shiny', 'rstudio')
Thanks, glad to have that one fixed!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With