R ggplot2没有';I don’我不知道如何处理课堂上的数据

R ggplot2没有';I don’我不知道如何处理课堂上的数据,r,shiny,R,Shiny,似乎反应性封装了变量,所以推文中的变量无法访问。。。那么如何修复它呢?还是不使用反应式 csv文件,仅用于2次上传 用户界面 服务器.r library(shiny) shinyServer(function(input, output) { library(lubridate) library(ggplot2) library(dplyr) library(readr) tweets_1 <- reactive({ req(input$file1)

似乎反应性封装了变量,所以推文中的变量无法访问。。。那么如何修复它呢?还是不使用反应式

csv文件,仅用于2次上传

用户界面

服务器.r

library(shiny)

shinyServer(function(input, output) {

  library(lubridate)
  library(ggplot2)
  library(dplyr)
  library(readr)

  tweets_1 <- reactive({
    req(input$file1)
    read.csv(input$file1$datapath)
  })

  tweets_2 <- reactive({
    req(input$file2)
    read.csv(input$file1$datapath)
  })  

    tweets <- reactive (
    as(bind_rows(tweets_1 %>% 
                          mutate(person = "satu"),
                        tweets_2 %>% 
                          mutate(person = "dua")) %>% 
    mutate(timestamp = ymd_hms(timestamp))))


    output$ditribusi <- renderPlot(
      ggplot(tweets, aes(x = timestamp, fill = person)) +
        geom_histogram(alpha = 0.5, position = "identity", bins = 20)
  )


})
库(闪亮)
shinyServer(功能(输入、输出){
图书馆(lubridate)
图书馆(GG2)
图书馆(dplyr)
图书馆(readr)
tweets_1%
变异(时间戳=ymd_hms(时间戳)))

output$ditribusi
reactive
返回一个reactive表达式,而不是一个值。基本上,这意味着可以通过调用它在reactive上下文(如
reactive
render*
等函数内)中访问它的当前值。我认为这个特定问题应该通过以下代码来解决:

shinyServer(function(input, output) {

  library(lubridate)
  library(ggplot2)
  library(dplyr)
  library(readr)

  tweets_1 <- reactive({
    req(input$file1)
    read.csv(input$file1$datapath)
  })

  tweets_2 <- reactive({
    req(input$file2)
    read.csv(input$file1$datapath)
  })

  tweets <- reactive(
    bind_rows(tweets_1() %>% 
                mutate(person = "satu"),
              tweets_2() %>% 
                mutate(person = "dua")) %>% 
      mutate(timestamp = ymd_hms(timestamp))
    )

  output$ditribusi <- renderPlot(
    ggplot(tweets(), aes(x = timestamp, fill = person)) +
      geom_histogram(alpha = 0.5, position = "identity", bins = 20)
  )
})
shinyServer(功能(输入、输出){
图书馆(lubridate)
图书馆(GG2)
图书馆(dplyr)
图书馆(readr)
tweets_1%
变异(时间戳=ymd_hms(时间戳))
)

输出$ditribusi您的回答给了我这个错误
警告:错误在.ident中:参数“Class”丢失,没有默认堆栈跟踪(最里面的第一个):
有什么建议如何修复它吗?
参数“Class”缺少,教程中没有默认的
,它只起作用…奇怪…这是因为在
tweets
定义中不必要的
as
功能。在编辑的答案中删除了它。
105: fortify.default
104: fortify
103: structure
102: ggplot.data.frame
101: ggplot.default
100: ggplot
 99: renderPlot
 89: <reactive:plotObj>
 78: plotObj
 77: origRenderFunc
 76: output$ditribusi
  1: runApp
shinyServer(function(input, output) {

  library(lubridate)
  library(ggplot2)
  library(dplyr)
  library(readr)

  tweets_1 <- reactive({
    req(input$file1)
    read.csv(input$file1$datapath)
  })

  tweets_2 <- reactive({
    req(input$file2)
    read.csv(input$file1$datapath)
  })

  tweets <- reactive(
    bind_rows(tweets_1() %>% 
                mutate(person = "satu"),
              tweets_2() %>% 
                mutate(person = "dua")) %>% 
      mutate(timestamp = ymd_hms(timestamp))
    )

  output$ditribusi <- renderPlot(
    ggplot(tweets(), aes(x = timestamp, fill = person)) +
      geom_histogram(alpha = 0.5, position = "identity", bins = 20)
  )
})