Error in derivePolygons: argument "data" is missing, with no default

52 views
Skip to first unread message

Jason Heppler

unread,
May 22, 2017, 1:19:04 PM5/22/17
to Shiny - Web Framework for R

Hi everyone,

I'm running into an error in my Shiny app and wondered if I could get some extra eyes on the issue.

The reproducible code is on Github: https://github.com/hepplerj/midwest-map-population

I am working on an interactive map of demographic change, and have one aspect of the map working fine (change in city population), but am struggling with an error in the choropleth I'm trying to create. I think the problem is either my draw_demographics() function, or an issue with my demographics_filtered() reactive (or both?)

Error stack:

> runApp()

Listening on http://127.0.0.1:4240
Parsed with column specification:
cols(
  id = col_integer(),
  st = col_character(),
  city = col_character(),
  cityst = col_character(),
  county_name = col_character(),
  year = col_integer(),
  population = col_integer(),
  lat = col_double(),
  lng = col_double()
)
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Warning: Error in derivePolygons: argument "data" is missing, with no default
Stack trace (innermost first):
    75: derivePolygons
    74: addPolygons
    73: function_list[[k]]
    72: withVisible
    71: freduce
    70: _fseq
    69: eval
    68: eval
    67: withVisible
    66: %>%
    65: draw_demographics [helpers.R#41]
    64: function_list[[k]]
    63: withVisible
    62: freduce
    61: _fseq
    60: eval
    59: eval
    58: withVisible
    57: %>%
    56: observerFunc [/Users/jheppler/Dropbox/github/midwest-map-population/server.R#116]
     1: runApp
ERROR: [on_request_read] connection reset by peer


Happy to answer questions, or take pointers on ways to troubleshoot. Thanks ahead of time!

Joe Cheng

unread,
May 22, 2017, 1:53:00 PM5/22/17
to Jason Heppler, Shiny - Web Framework for R
If you look at the stack trace, you can see the line of code that is causing the problem. In this case it's server.R#116, a call to draw_demographics that's missing the "input" argument. I get another error after fixing that though; I feel like you'll be able to figure it out if you similarly look at the stack trace looking for lines from server.R/helpers.R.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/055d219b-9d5f-41f0-b101-70e9908baab9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Heppler

unread,
May 22, 2017, 2:33:00 PM5/22/17
to Shiny - Web Framework for R, jason....@gmail.com
Thanks for taking a look. I think I found the problem you mention, but now ended up with Error in [[: subscript out of bounds. I assume there's an issue here with my function not getting the default selectInput()?

Joe Cheng

unread,
May 22, 2017, 2:39:56 PM5/22/17
to Jason Heppler, Shiny - Web Framework for R
Try print(input$year) there and see what it says?

Jason Heppler

unread,
May 22, 2017, 2:57:06 PM5/22/17
to Shiny - Web Framework for R, jason....@gmail.com
From inside the observe() for draw_demographics(), I get "1810", which is correct.

From within draw_demographics(), I also get "1810".

From within demographics_filtered() reactive, I also get "1810".

Joe Cheng

unread,
May 22, 2017, 9:20:20 PM5/22/17
to Jason Heppler, Shiny - Web Framework for R
It's because input$year is numeric, not character. counties[[as.character(input$year)]] works.

demographics_filtered also had a line with just `input$population`, which seems wrong? Also I get these warnings:

Warning in colorNumeric("Blues", NULL, n = 9) :
  partial argument match of 'n' to 'na.color'

which is definitely wrong, there's no n parameter. And also some warnings about polygon edges from output$cities_hist.

Jason Heppler

unread,
May 23, 2017, 10:48:28 AM5/23/17
to Shiny - Web Framework for R, jason....@gmail.com
Awesome, thanks so much for spotting that! I think I'm extremely close to having this thing working finally. I really appreciate it!

I have a related question: for the coloring of polygons, I need to make sure the color scale changes based on user input (e.g., whether one is looking at total population, population density, and so on). It doesn't seem to work if I pass input to draw_demographics(), for example

pal <- colorQuantile("YlGnBu", domain = input$population, n = 7)

Does pal in this case need to become a reactive? So, something like

pal <- colorQuantile("YlGnBu", domain = paste0(input$population), n = 7)

That didn't seem to work for me, but I feel like I'm on the right track...

Thanks again!

Joe Cheng

unread,
May 23, 2017, 1:12:40 PM5/23/17
to Jason Heppler, Shiny - Web Framework for R
The domain argument needs to be a vector of numbers, whereas I think input$population is just a name.

Also I noticed that you're using "population" as the id for both a uiOutput and a selectInput. Please make sure that all input and output id's are unique across your app--if it's working today, it's only by accident!

Reply all
Reply to author
Forward
0 new messages