Leaflet Plot Points in Shiny R Tab

328 views
Skip to first unread message

Brian Tat

unread,
Mar 7, 2015, 7:04:15 PM3/7/15
to shiny-...@googlegroups.com

So I have been playing around with Super Zip in ShinyR.

http://jcheng.shinyapps.io/superzip/

https://github.com/jcheng5/superzip

I was wondering if there was a way to switch the tabs of Map and Data Explorer.

It's not a simple switch, since when doing so, the points do not plot on the map if the tabPanels are switched in order.



Yihui Xie

unread,
Mar 8, 2015, 10:11:04 AM3/8/15
to Brian Tat, shiny-discuss
Could you prepare a minimal reproducible example? Thanks!

Regards,
Yihui

Brian Tat

unread,
Mar 8, 2015, 5:36:25 PM3/8/15
to shiny-...@googlegroups.com, tatzt...@gmail.com
Hi Yihui, 

I have prepared a smaller example of my problem here: 


Sincerely,
Brian Tat

Joe Cheng

unread,
Mar 10, 2015, 7:20:00 PM3/10/15
to Brian Tat, shiny-...@googlegroups.com
On line 15 of server.R, can you try this?

outputOptions(output, "map", suspendWhenHidden=FALSE)

--
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/65d863da-f66a-4436-946f-7136f1203a6f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Brian Tat

unread,
Mar 10, 2015, 8:06:04 PM3/10/15
to shiny-...@googlegroups.com, tatzt...@gmail.com
Hi Joe, 

It seems that all of the points show up! But the map itself gets distorted when putting that line unless you readjust the window. 

Thanks for the solution!

Sincerely,
Brian Tat

Yihui Xie

unread,
Mar 16, 2015, 12:20:29 PM3/16/15
to Brian Tat, shiny-discuss
Yes I can reproduce the problem. I just realized you were using the
old leaflet package (https://github.com/jcheng5/leaflet-shiny). I
tested the new one (https://github.com/rstudio/leaflet), and it seems
to be working well in your case. The syntax is a little bit different,
though.

# ui.R
library(shiny)
library(leaflet)

navbarPage(
"Reading Is Fundamental", id="nav",
tabPanel("Hello World!", h4("Hello.")),
tabPanel(
"Map",
div(
class="outer",
tags$head(
# Include our custom CSS
includeCSS("styles.css"),
includeScript("gomap.js")
),
leafletOutput('map')
)
)#,
#tabPanel("Hello World!",h4("Hello."))
)


# server.R
library(shiny)
library(leaflet)

data <- read.csv("data/final_data.csv")
all_data <- data[1:500,]

shinyServer(function(input, output,session) {

output$map <- renderLeaflet({
leaflet(all_data) %>% addTiles(
urlTemplate =
"//{s}.tiles.mapbox.com/v3/jcheng.map-5ebohr46/{z}/{x}/{y}.png",
attribution = HTML('Maps by <a href="http://www.mapbox.com/">Mapbox</a>')
) %>% setView(-118.399373, 34.052363, zoom = 10) %>%
addCircles(radius = 100)
})

})


Regards,
Yihui
server.R
ui.R
Reply all
Reply to author
Forward
0 new messages