Shiny不显示R plotly plot

时间:2017-04-21 14:13:00

标签: r shiny shiny-server r-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页面中。

感谢您的帮助!

1 个答案:

答案 0 :(得分:6)

您正在使用plotly,因此请使用renderPlot更改renderPlotly

output$plot2 <- renderPlotly({