1

I am relatively new to R, and very new to Shiny, but I have not been able to find info on this error.

I created two graphs, one using d3heatmap and one using leaflet. When I run the scripts individually, they both work. I followed instructions and used boostrapPage() to have the two charts display together with shiny.

The code can be found here: https://github.com/jotasolano/dengueCR but I'll paste it below anyway. I get the error message

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

on the popup window that should display the chart (NOT on the console). Any Ideas as to why this is happening?

server.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")
  )
))

Also, if you see any terrible practice, please feel free to note, because like I said, I am relatively new and documentation is messy sometimes.

Thank you!

JotaSolano
  • 65
  • 9
  • P.S. I followed these instructions http://stackoverflow.com/questions/21895321/shiny-rcharts-multiple-chart-output – JotaSolano Feb 20 '16 at 00:43

1 Answers1

1

I think you are using some dated functions. Both leaflet and d3heatmap have their own rendering/output functions based on htmltools. Change your UI to

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

I would also take the data processing outside of the the reactives since it doesn't change, either putting it in your server or in the global.R that gets read at startup.

With these minor mods, your server could be

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
  })
}
Rorschach
  • 31,301
  • 5
  • 78
  • 129
  • This worked great! Thank you so much. So now every package has its own `packageOutput` function? Also, this is not exactly related, but I am getting one chart below the other one, instead of one next to the other one. Any ideas why this is happening? I am using only one row. Here's a screen cap http://imgur.com/nOgDBRw – JotaSolano Feb 20 '16 at 06:12
  • Awesome, it works great. It's annoying to be following outdated documentation, even [the official documentation](http://shiny.rstudio.com/articles/layout-guide.html) uses `shinyUI()` but the IDE tells me it's now outdated. Thanks again! – JotaSolano Feb 21 '16 at 00:29