【问题标题】:Shiny not outputing when using showOutput and multiple charts使用显示输出和多个图表时闪亮不输出
【发布时间】:2016-06-01 18:04:40
【问题描述】:

我对 R 比较陌生,对 Shiny 也很陌生,但我无法找到有关此错误的信息。

我创建了两张图表,一张使用d3heatmap,一张使用leaflet。当我单独运行脚本时,它们都可以工作。我按照说明使用boostrapPage() 将两个图表与闪亮一起显示。

代码可以在这里找到:https://github.com/jotasolano/dengueCR 但无论如何我都会把它粘贴在下面。我收到错误消息

ERROR: path[1]="": No such file or directory

在应该显示图表的弹出窗口上(不在控制台上)。关于为什么会发生这种情况的任何想法?

服务器.R:

library(dplyr)
library(d3heatmap)
library(RColorBrewer)
library(shiny)
library(leaflet)
library(rCharts)

function(input, output, session) {
  output$heatmap <- renderD3heatmap({

    #convert to df and drop total
    cases <- read.csv("casos_2015.csv") %>%
      select(-Total) %>%
      select(-Semana)


    d3heatmap(cases, scale = "row",
              dendrogram = "none",
              color = scales::col_quantile("Reds", NULL, 10),
              xaxis_font_size = "10px",
              show_grid = 0.2)
  })

  output$geomap <- renderPlot({
    data <- read.csv("cantones.csv")

    casos_popup <- paste0("<strong>Canton:  </strong>", data$canton,
                          "<br><strong>Cases:  </strong>", data$casos,
                          "<br><strong>Rate:  </strong>", signif(data$tasa, 3))

    m <- leaflet(data) %>%
      addProviderTiles("CartoDB.Positron") %>%
        addCircles(~lng,
                   ~lat,
                   popup = casos_popup,
                   radius = ~sqrt(casos) * 300,
                   weight = 1,
                   color = "red")
  })
}

ui.R:

library(shiny)
library(d3heatmap)
library(leaflet)
library(rCharts)

bootstrapPage(mainPanel(width = 12, 
  div(class = "row",
      div(showOutput("heatmap", "d3heatmap"), class = "span6"),
      div(showOutput("geomap", "leaflet"), class = "span6")
  )
))

另外,如果您看到任何糟糕的做法,请随时注意,因为就像我说的,我相对较新,有时文档很混乱。

谢谢!

【问题讨论】:

标签: r charts shiny


【解决方案1】:

我认为您正在使用一些过时的功能。 Leaflet 和 d3heatmap 都有自己的基于 htmltools 的渲染/输出功能。将您的用户界面更改为

bootstrapPage(mainPanel(width = 12, 
  div(class = "row",
    div(d3heatmapOutput("heatmap"), class = "span6"),
    div(leafletOutput("geomap"), class = "span6")
  )
))

我也会在响应式之外进行数据处理,因为它不会改变,要么将它放在你的服务器中,要么放在启动时读取的 global.R 中。

有了这些小模组,你的服务器就可以

library(dplyr)
library(d3heatmap)
library(RColorBrewer)
library(shiny)
library(leaflet)
library(rCharts)

cases <- read.csv("casos_2015.csv") %>%
  select(-Total) %>%
  select(-Semana)

## I would add the labels here as well unless those are subject to change
data <- read.csv("cantones.csv")

function(input, output, session) {

  output$heatmap <- renderD3heatmap({

    d3heatmap(cases, scale = "row",
              dendrogram = "none",
              color = scales::col_quantile("Reds", NULL, 10),
              xaxis_font_size = "10px",
              show_grid = 0.2)
  })

  output$geomap <- renderLeaflet({
    casos_popup <- paste0("<strong>Canton:  </strong>", data$canton,
                          "<br><strong>Cases:  </strong>", data$casos,
                          "<br><strong>Rate:  </strong>", signif(data$tasa, 3))

    m <- leaflet(data) %>%
      addProviderTiles("CartoDB.Positron") %>%
        addCircles(~lng,
                   ~lat,
                   popup = casos_popup,
                   radius = ~sqrt(casos) * 300,
                   weight = 1,
                   color = "red")
    m
  })
}

【讨论】:

  • 这很棒!太感谢了。那么现在每个包都有自己的packageOutput 函数了吗?此外,这并不完全相关,但我得到一张图表低于另一张图表,而不是一张紧挨着另一张图表。任何想法为什么会发生这种情况?我只使用一排。这是屏幕截图imgur.com/nOgDBRw
  • 太棒了,效果很好。关注过时的文档很烦人,即使 the official documentation 使用 shinyUI() 但 IDE 告诉我它现在已经过时了。再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-06
  • 1970-01-01
  • 2023-03-30
  • 2017-05-15
  • 2015-08-11
相关资源
最近更新 更多