条形图未在闪亮的Web应用程序中显示

时间:2020-05-10 16:59:34

标签: r shiny plotly shinydashboard

我正在尝试在Web应用程序中显示条形图,但有一个白色区域。我在应用程序代码工作之外查看了我的代码。问题是什么?救命? 我的条形图代码

output$revenuebyPrd <- renderPlot({
    plot_ly(data,
      x = ~company_name,
      y = ~revenue,
      type = "bar"
    )
  })

我的数据可以帮助您

mydb = dbConnect(MySQL(), user='root', password='xxxx', dbname='app', host='localhost')
  on.exit(dbDisconnect(mydb), add = TRUE)
  rs=dbGetQuery(mydb, "SET NAMES 'cp1251'") 
  rs=dbSendQuery(mydb,"select * from companies")
  data=fetch(rs,n=-1)
  rs1=dbSendQuery(mydb,"select revenue from companies")
  revenue=fetch(rs1,n=-1)
  rs2=dbSendQuery(mydb,"select industry from companies")
  industry=fetch(rs2,n=-1)
  rs3=dbSendQuery(mydb,"select company_name from companies")
  industry=fetch(rs3,n=-1)

闪亮

enter image description here

没有光泽

enter image description here

1 个答案:

答案 0 :(得分:1)

在Shiny应用程序的服务器端呈现对象时,您需要使用随附的render_()函数。例如,要渲染数据框,请使用renderTable()。如果您尝试从第三方程序包(例如DT,Plotly)渲染对象,并且该对象与Shiny兼容,则该程序包应包含随附的render_()函数(例如DT::renderDT(),{ {1}}。

在您的情况下,您正在使用第三方程序包“ plotly”。 Plotly随附有随附的 plotly::renderPlotly() renderPlotly() 功能,可用于Shiny。因此,您的代码应如下所示:

plotlyOutput()