r - Shiny 不显示 R 绘图

标签 r shiny shiny-server r-plotly

我对 Shiny 还很陌生,并试图覆盖用情节制作的饼图。 单击 runapp 后,呈现的 html 仅包含标题,即“Plotly”

代码如下

用户界面

library(shiny)

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

服务器

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,因此将 renderPlot 更改为 renderPlotly:

output$plot2 <- renderPlotly({

关于r - Shiny 不显示 R 绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43544935/

相关文章:

R-创建按列名称选择数据框中整行的函数

R - 从大型栅格(不包括 NA 值)高效创建数据帧

R Shiny 仪表板仅加载一次选项卡

r - 使用 plotly 和 Shiny 服务器复制图例条目

r - 如果没有可用的 UI 输入,则防止在 Shiny 中发生事件

r - 在 OS X Yosemite 上安装 RODBC

html - Shiny :侧边栏和 "sentence"之间的空格

r - 提高 R Shiny 传单 map 的速度

r - Shiny 的应用程序中的图像输出

shiny - 在没有 Shiny 服务器的情况下托管 Shiny 应用程序