'闪亮'R包如何处理数据帧?

use*_*990 11 twitter web-applications r dataframe shiny

我正在构建一个使用'twitteR'R包下载推文的网络应用程序,修改这些推文并通过"闪亮的"R网络应用程序显示它们.执行下载和处理推文到数据框的代码没有问题:

do.call('rbind', lapply(userTimeline('nutwition_log'), as.data.frame))
Run Code Online (Sandbox Code Playgroud)

...你可以在你的终端(加载了twitteR库)中运行它,并看到它下载了推文数据并将结果数据框打印到屏幕上.

但是,当我在"闪亮"应用程序(服务器端)中使用此类调用时......例如......


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)
  })

})
Run Code Online (Sandbox Code Playgroud)

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")
  )
))
Run Code Online (Sandbox Code Playgroud)

...我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

...我想要做的就是能够更改正在下载和发送推文的用户,然后输出结果数据框(... datasetInput()返回,加载到output$view)mainPanel().我不知道为什么这不起作用.

任何帮助都会很棒!

Joe*_*eng 10

我想我已经知道了:https://github.com/rstudio/shiny/commit/0b469f09df7e2ca3bbdb2ddadc8473a8126a9431

在对此进行适当测试并将其转换为新的Shiny构建之前,您可以使用devtools直接从GitHub进行测试:

library(devtools)
install_github('shiny', 'rstudio')
Run Code Online (Sandbox Code Playgroud)

谢谢,很高兴有一个固定!


Bra*_*sen 6

我不确定这是不是一个错误,但这里肯定有一些奇怪的事情,Joe Cheng和他.我想知道.它的工作原理如下:

server.R

library(shiny)
library(twitteR)
shinyServer(function(input, output) {

  datasetInput <- reactive(function() {
    tweets <- userTimeline(input$subscriber)
    tmp <- lapply(1:length(tweets),function(x) data.frame(
      text=tweets[[x]]$text,
      created=tweets[[x]]$created,
      screename=tweets[[x]]$getScreenName()))

    do.call(rbind,tmp)
  })

  output$view <- reactiveTable(function() {
    head(datasetInput(), n = input$obs)
  })

})
Run Code Online (Sandbox Code Playgroud)

所以这不是data.frames的问题,而是与twitteR为引用类对象设置方法的方式有关status.通过访问器引用字段来运行完全相同的代码似乎运行得很好.

感觉像"又一个S4 /参考类之谜".