Sidebar overlaid on a Leaflet map

1,084 views
Skip to first unread message

Michael G.

unread,
Nov 17, 2013, 8:24:29 PM11/17/13
to shiny-...@googlegroups.com
First, RStudio, thank you so much for shiny! 

I've spent some hours trying to get a Leaflet map to take up the full window with the sidebar panel (and its content) overlaid on top. Similar to this: http://maps.mixedbredie.net/leaflet/index2.html
I've played with the CSS but i've only managed to stumble: setting html, body height to 100% and the #map to the same.. but only to have my map disappear)

I was hoping if someone may lend a hand--Below are the files I am playing with.
Thank you!

# server.r
library(shiny)
shinyServer(function(input, output) {})

# ui.r
library(shiny)

shinyUI(pageWithSidebar(

  headerPanel(
tags$link(rel="stylesheet", type="text/css", href="styles.css"),
  ),

  sidebarPanel(
  p("Content")
  ),

  mainPanel(
  includeHTML("mapper.html"),
  includeScript("./www/map.js")

  )
))

<!-- mapper.html -->
<script type="text/javascript" src="http://maps.stamen.com/js/tile.stamen.js?v1.2.3"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />

<div id="map"></div>


// map.js
var layer = new L.StamenTileLayer("toner-lite");
var map = new L.Map("map", {
    center: new L.LatLng(39.3199, -76.6167),
    zoom: 5,
    maxZoom: 10
});

map.addLayer(layer);

/*styles.css*/
#map { height: 700px; }



Ramnath Vaidyanathan

unread,
Nov 17, 2013, 9:23:22 PM11/17/13
to shiny-...@googlegroups.com
You can do this with rCharts (http://rcharts.io), an R package that I authored which provides bindings to multiple js viz libraries. Here is the code that will get you a fullscreen map in your app. Note that you will need to install the `dev` branch of `rCharts` from `github` to be able to use this.

library(shiny)
# devtools::install_github("rCharts", "ramnathv", ref = "dev")
library(rCharts)
runApp(list(
ui = bootstrapPage(
mapOutput("mymap")
),
server = function(input, output, session){
output$mymap <- renderMap({
L1 <- Leaflet$new()
L1$setView(c(39.3199, -76.6167), 10)
L1$tileLayer(provider = 'Stamen.TonerLite')
L1$set(width = 1600, height = 800)
L1
})
}
))
Reply all
Reply to author
Forward
0 new messages