leaflet error with Shiny server

209 views
Skip to first unread message

Carlos Sánchez

unread,
Jul 20, 2015, 7:51:17 AM7/20/15
to shiny-...@googlegroups.com
Hi,

I have basically copied and pasted this example from the RStudio Leaftet page.

ui.R is as follows

library(shiny)
library
(leaflet)
library
(RColorBrewer)

bootstrapPage
(
  tags$style
(type = "text/css", "html, body {width:100%;height:100%}"),
  leafletOutput
("map", width = "100%", height = "100%"),
  absolutePanel
(top = 10, right = 10,
                sliderInput
("range", "Magnitudes", min(quakes$mag), max(quakes$mag),
                            value
= range(quakes$mag), step = 0.1
               
),
                selectInput
("colors", "Color Scheme",
                            rownames
(subset(brewer.pal.info, category %in% c("seq", "div")))
               
),
                checkboxInput
("legend", "Show legend", TRUE)
 
)
)

server.R is as follows:

server
<- function(input, output, session) {
 
 
# Reactive expression for the data subsetted to what the user selected
  filteredData
<- reactive({
    quakes
[quakes$mag >= input$range[1] & quakes$mag <= input$range[2],]
 
})
 
 
# This reactive expression represents the palette function,
 
# which changes as the user makes selections in UI.
  colorpal
<- reactive({
    colorNumeric
(input$colors, quakes$mag)
 
})
 
  output$map
<- renderLeaflet({
   
# Use leaflet() here, and only include aspects of the map that
   
# won't need to change dynamically (at least, not unless the
   
# entire map is being torn down and recreated).
    leaflet
(quakes) %>% addTiles() %>%
      fitBounds
(~min(long), ~min(lat), ~max(long), ~max(lat))
 
})
 
 
# Incremental changes to the map (in this case, replacing the
 
# circles when a new color is chosen) should be performed in
 
# an observer. Each independent set of things that can change
 
# should be managed in its own observer.
  observe
({
    pal
<- colorpal()
   

    leafletProxy
("map", data = filteredData()) %>%
      clearShapes
() %>%
      addCircles
(radius = ~10^mag/10, weight = 1, color = "#777777",
                 fillColor
= ~pal(mag), fillOpacity = 0.7, popup = ~paste(mag)
     
)
 
})
 
 
# Use a separate observer to recreate the legend as needed.
  observe
({
    proxy
<- leafletProxy("map", data = quakes)
   
   
# Remove any existing legend, and only if the legend is
   
# enabled, create a new one.
    proxy
%>% clearControls()
   
if (input$legend) {
      pal
<- colorpal()
      proxy
%>% addLegend(position = "bottomright",
                          pal
= pal, values = ~mag
     
)
   
}
 
})
}

Everything runs fine locally but I get a very non-descriptive error if I run the app via shiny server which seems to point to leafletProxy as the source of the error:

"
Listening on http://127.0.0.1:55286
Warning: Unhandled error in observer: wrong arguments for subsetting an environment
observe({
    pal <- colorpal()
    leafletProxy("
map", data = filteredData()) %>% clearShapes() %>%
        addCircles(radius = ~10^mag/10, weight = 1, color = "
#777777",
            fillColor
= ~pal(mag), fillOpacity = 0.7, popup = ~paste(mag))
})
"

Any ideas what might be causing the problem? I am using the same machine to run locally and via Shiny server.

Thanks,

Carlos



Paul Viefers

unread,
Jul 27, 2015, 3:31:51 AM7/27/15
to Shiny - Web Framework for R, car...@xray-imatek.com
Get the same error, also after a thorough reinstallation of R, RStudio and Rtools. Problem is with leaftProxy(), as soon as I include it in the code, the mentioned error is returned.
Sorry, no solution so far.

Best
Paul

Carlos Sánchez

unread,
Jul 27, 2015, 3:40:00 PM7/27/15
to Paul Viefers, Shiny - Web Framework for R
Hi,

Yeah, I don't really know what the problem might be. But, I now think leafletProxy() is not the problem. If you split up those lines, you'll see everything explodes with the clearControls() or addCircles() commands. It is all very strange.

Carlos
--

------------------------------------------------------------------------------
Carlos Sánchez
X-Ray Imatek S.L.
Edificio Eureka, Oficina PBM4.1 - Campus UAB
08193 Bellaterra (Barcelona). Spain
Tel: (+34) 93.586.89.61 
 
------------------------------------------------------------------------------

Este mensaje se dirige exclusivamente a su destinatario y puede contener información privilegiada o confidencial. Si no es vd. el destinatario indicado, queda notificado de que la utilización, divulgación y/o copia sin autorización está prohibida en virtud de la legislación vigente. Si ha recibido este mensaje por error, le rogamos que nos lo comunique inmediatamente por esta misma vía y proceda a su destrucción.

Aquest missatge es dirigeix exclusivament al seu destinatari o pot contenir informació privilegiada o confidencial. Si vostè no és el destinatari indicat, resta notificat de que la utilització, divulgació i/o còpia sense autorització està prohibida en virtut de la legislació vigent. Si ha rebut aquest missatge per error, preguem ens ho comuniqui immediatament per aquesta mateixa via i procedeixi a la seva destrucció.

This message is intended exclusively for its addressee and may contain information that is confidential and protected by professional privilege. If you are not the intended recipient you are hereby notified that any dissemination, copy or disclosure of this communication is strictly prohibited by law. If this message has been received in error, please immediately notify us via e-mail and delete it.


Fereshteh Karimeddini

unread,
Jul 27, 2015, 5:19:59 PM7/27/15
to Shiny - Web Framework for R, paulv...@gmail.com, car...@xray-imatek.com
Carlos, 

I am able to run your code on Shiny Server with no issues. I think Joe had already responded to you in another thread and said the same thing. 

It is possible that certain version of packages cause the problem. Here is my environment:

Shiny Server v1.4.0.721
shiny  '0.12.1'
leaflet '1.0.0'
RColorBrewer '1.0.5'

What version of these (or possibly other dependent) packages are you running?


Fereshteh

Carlos Sánchez

unread,
Jul 27, 2015, 5:59:27 PM7/27/15
to Fereshteh Karimeddini, Shiny - Web Framework for R, Paul Viefers
Hi Fereshteh,

Thanks for the pointers. I checked and I was running shiny 0.11 with an older version of htmlwidgets. This is probably the cause of the problem. Anyway, I upgraded to shiny 0.12.1 and htmlwidgets 0.5 and everything is running like a charm.

Thanks a lot for your help.

Carlos

Reply all
Reply to author
Forward
0 new messages