2017-04-21 240 views
3

我是闪闪发光的新尝试,试图推动一个阴谋制作的饼图。 一旦点击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页面中。

感谢您的帮助!

+0

本地工作现在, 但一旦公布它说从断开服务器 –

回答

4

您使用plotly,所以更改renderPlotrenderPlotly

output$plot2 <- renderPlotly({ 
+0

嗨,我尝试使用renderplotly但它仍然不显示图表 –

+1

在'UI'''' plotlyOutput''而不是'plotOutput' –

+0

谢谢,现在在本地工作, ,但一旦发布页面会变灰,并说与服务器断开连接 –