繁体   English   中英

Shiny 不显示 R 情节图

[英]Shiny doesn't display R plotly plot

我对闪亮的东西还很陌生,并试图推动用 plotly 制作的饼图。 单击 runapp 后,呈现的 html 仅包含标题,即“Plotly”

代码如下

UI

library(shiny)

shinyUI <- fluidPage(  
  titlePanel("Plotly"),
  mainPanel(
  plotOutput("plot2")))

Server

library(shiny)
library(ggplot2)
library(ggthemes)
library(plotly)
library(shiny)
library(ggthemes)
library(RODBC)
library(magrittr)

synddb <- odbcConnect("Syndromic", uid="uname", pwd="pwd", believeNRows=FALSE)
totalcomplaints<-sqlQuery(channel=synddb,query= "select c.siteid,count(c.siteid) number_of_complaints, s.sitefullname from complainttmp c, site s
                          where s.siteid= c.siteid and c.siteid in(1,2,3,4,5,6,7,8, 10,11,19,20)
                          group by c.siteid,s.sitefullname
                          order by c.siteid asc")


shinyServer <- function(input, output) {
  output$plot2 <- renderPloty({
    print(
      plot_ly(totalcomplaints,labels=paste(totalcomplaints$sitefullname,totalcomplaints$siteid,sep = "-"),values = ~number_of_complaints, type = 'pie',
              textposition = 'inside',
              textinfo = 'label+percent+values',
              insidetextfont = list(color = '#FFFFFF'),
              hoverinfo = 'text',
              text = ~paste( number_of_complaints, 'complaints'),
              marker = list(colors = colors,
                            line = list(color = '#000000', width = 1)),
              showlegend = T) %>%
        layout(title = 'Complaints in Percentage',
               xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
               yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE)))
  })

}

运行应用程序后,我确实在查看器中看到了绘图,但它没有出现在它呈现的 HTML 页面中。

您正在使用plotly ,所以更改renderPlotrenderPlotly

output$plot2 <- renderPlotly({

这节省了我的时间。 plotlyOutput() 取消服务器上的 ui 和 renderPlotly()。

非常感谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM