Skip to content

Instantly share code, notes, and snippets.

@sckott
Created June 5, 2013 21:20
Show Gist options
  • Save sckott/5717419 to your computer and use it in GitHub Desktop.
Save sckott/5717419 to your computer and use it in GitHub Desktop.
trying a rcharts map in a panel - not working for me at least
require(shiny)
require(rCharts)
renderMap = function(expr, env = parent.frame(), quoted = FALSE){
func <- shiny::exprToFunction(expr, env, quoted)
function() {
rChart_ <- func()
map_div = sprintf('<div id="%s" class="rChart leaflet"></div>', rChart_$params$dom)
HTML(paste(c(map_div, rChart_$html()), collapse = '\n'))
}
}
shinyServer(function(input, output){
output$chart <- renderMap({
require(rCharts)
map3 <- Leaflet$new()
map3$setView(c(51.505, -0.09), zoom = 13)
map3$tileLayer(provider = input$provider, urlTemplate = NULL)
map3$marker(c(51.5, -0.09), bindPopup = "<p> Hi. I am a popup </p>")
map3$marker(c(51.495, -0.083), bindPopup = "<p> Hi. I am another popup </p>")
map3
})
})
require(shiny)
require(rCharts)
mapOutput = function(outputId){
LIB <- get_lib('leaflet')
suppressMessages(singleton(addResourcePath(LIB$name, LIB$url)))
div(id = outputId, class = paste("shiny-html-output", basename(LIB$name)),
tagList(get_assets_shiny(LIB)))
}
shinyUI(pageWithSidebar(
headerPanel('Leaflet Maps'),
sidebarPanel(
selectInput('provider', 'Provider',
choices = c('Stamen.Toner', 'MapQuestOpen.OSM'),
selected = 'MapQuestOpen.OSM'
)
),
mainPanel(
tabsetPanel(
tabPanel("thing1", mapOutput('chart')),
tabPanel("thing2", mapOutput('chart'))
))
))
@natalyoussef
Copy link

I am also trying to create a Shiny app using rMaps, but still running into issues. Were you able to get your code running?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment