【问题标题】:no applicable method for 'ggplotly' applied to an object of class "NULL"没有适用于 'ggplotly' 的方法应用于“NULL”类的对象
【发布时间】:2023-03-13 00:04:02
【问题描述】:

我得到这个错误我错了

library(RJDBC)
library(dplyr)
library(shiny)
library(ggplot2)
library(scales)
library(shinydashboard)
library(gridExtra)
library(DT)

ggplotly 不工作我做错了什么无法得到它

output$plot1 <- renderPlotly({
      if (is.null(input$sector) ){return()
      } else if(input$sector == "pick one") { return()
      } else p1 <-**ggplotly**(ggplot(data = subdata1() ,aes(x=SaleDate,y=Total))+  geom_point(stat='summary', fun.y=sum) +
          geom_line(colour = "red")+geom_hline(aes(yintercept = mean(Total)),colour = "blue")+ geom_text(data = subdata1(), aes(label = Total), 
                                                 position=position_jitter(width=1,height=0.8),  size=3)))+ scale_y_continuous(labels = scales::comma)
          labs(x = "SaleDate",
               y = "Total")
      print(p1 + theme(axis.text.x =
                         element_text(size  = 10,angle = 45,hjust = 1,vjust = 1)))

      }) 

【问题讨论】:

    标签: r ggplot2 shiny plotly


    【解决方案1】:

    您似乎没有在库列表中加载 plotly 包。试试加载?

     library(plotly)
    

    【讨论】:

    • 我忘了说,但它在那里
    • 可能是版本不一致:)
    【解决方案2】:

    这可能是旧线程,但答案可能会在将来帮助某人。如果您调整窗口大小,似乎有时会随机弹出此问题。这是github 使用 ggplot 的相同错误的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-15
      • 2022-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-24
      • 1970-01-01
      相关资源
      最近更新 更多