Skip to content

Instantly share code, notes, and snippets.

@hafen
Created October 8, 2015 18:59
Show Gist options
  • Save hafen/157d7eb4dc01c15ad3b9 to your computer and use it in GitHub Desktop.
Save hafen/157d7eb4dc01c15ad3b9 to your computer and use it in GitHub Desktop.
rbokeh gmap test
# devtools::install_github("bokeh/rbokeh@dev")
library(rbokeh)
library(maps)

m <- map("state", region = "colorado", plot = FALSE)
mx <- mean(range(m$x, na.rm = TRUE))
my <- mean(range(m$y, na.rm = TRUE))
gmap(lng = mx, lat = my, zoom = 6, width = 800) %>% 
  ly_lines(m$x, m$y, line_width = 2)
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.pydata.org/bokeh/release/bokeh-0.10.0.min.js"></script>
<link href="http://cdn.pydata.org/bokeh/release/bokeh-0.10.0.min.css" rel="stylesheet">
</head>
<body>
<div id="8fc67c13aca2ec13a3051c9d728d2bb1" class="plotdiv"></div>
<script type="text/javascript">
Bokeh.$(function() {
var modelid = "8dbf065b05f449b6a3e4e3eddd7dab70";
var modeltype = "GMapPlot";
var elementid = "8fc67c13aca2ec13a3051c9d728d2bb1";
Bokeh.logger.info("Realizing plot:");
Bokeh.logger.info(" - modeltype: GMapPlot");
Bokeh.logger.info(" - modelid: 8dbf065b05f449b6a3e4e3eddd7dab70");
Bokeh.logger.info(" - elementid: 8fc67c13aca2ec13a3051c9d728d2bb1");
var all_models = [{"type":"GMapPlot","id":"8dbf065b05f449b6a3e4e3eddd7dab70","attributes":{"title":null,"id":"8dbf065b05f449b6a3e4e3eddd7dab70","plot_width":790,"plot_height":434,"x_range":{"type":"Range1d","id":"29708b6135c31d54d095eab825018b27"},"y_range":{"type":"Range1d","id":"bc22d0ee625cab3cf1182c59d13b8b60"},"left":[{"type":"LinearAxis","id":"c1b9a7c921e6162b62c8294341550293"}],"below":[{"type":"LinearAxis","id":"de9180cfd33e41402c266a85d37c1bfb"}],"right":[],"above":[],"renderers":[{"type":"GlyphRenderer","id":"142b82f7d09cd4f539257060e912af31"},{"type":"LinearAxis","id":"de9180cfd33e41402c266a85d37c1bfb"},{"type":"LinearAxis","id":"c1b9a7c921e6162b62c8294341550293"}],"tools":[{"type":"PanTool","id":"2cfe074deffdc7e19e515655466db780"},{"type":"WheelZoomTool","id":"0e3c9ade817d536b576b021407cc3bac"},{"type":"BoxZoomTool","id":"62ed5c7b6c1a0be613f1871a206bc096"},{"type":"ResizeTool","id":"05ed91537e4651b514f1d51d907238ad"},{"type":"ResetTool","id":"95fa920cf7eaa61ee5d073318b0f4f5a"},{"type":"PreviewSaveTool","id":"5cb11925d204de785aba91cebea1de7e"}],"tool_events":{"type":"ToolEvents","id":"367cb344f61a208a64c9be900b7d7c04"},"extra_y_ranges":{},"extra_x_ranges":{},"tags":[],"doc":null,"min_border":4,"lod_threshold":null,"map_options":{"lat":39.0012,"lng":-105.5532,"zoom":6,"map_type":"hybrid"}}},{"type":"PanTool","id":"2cfe074deffdc7e19e515655466db780","attributes":{"id":"2cfe074deffdc7e19e515655466db780","tags":[],"doc":null,"plot":{"type":"GMapPlot","id":"8dbf065b05f449b6a3e4e3eddd7dab70"},"dimensions":["width","height"]}},{"type":"ToolEvents","id":"367cb344f61a208a64c9be900b7d7c04","attributes":{"id":"367cb344f61a208a64c9be900b7d7c04","tags":[],"doc":null},"geometries":[]},{"type":"WheelZoomTool","id":"0e3c9ade817d536b576b021407cc3bac","attributes":{"id":"0e3c9ade817d536b576b021407cc3bac","tags":[],"doc":null,"plot":{"type":"GMapPlot","id":"8dbf065b05f449b6a3e4e3eddd7dab70"},"dimensions":["width","height"]}},{"type":"BoxZoomTool","id":"62ed5c7b6c1a0be613f1871a206bc096","attributes":{"id":"62ed5c7b6c1a0be613f1871a206bc096","tags":[],"doc":null,"plot":{"type":"GMapPlot","id":"8dbf065b05f449b6a3e4e3eddd7dab70"}}},{"type":"ResizeTool","id":"05ed91537e4651b514f1d51d907238ad","attributes":{"id":"05ed91537e4651b514f1d51d907238ad","tags":[],"doc":null,"plot":{"type":"GMapPlot","id":"8dbf065b05f449b6a3e4e3eddd7dab70"}}},{"type":"ResetTool","id":"95fa920cf7eaa61ee5d073318b0f4f5a","attributes":{"id":"95fa920cf7eaa61ee5d073318b0f4f5a","tags":[],"doc":null,"plot":{"type":"GMapPlot","id":"8dbf065b05f449b6a3e4e3eddd7dab70"}}},{"type":"PreviewSaveTool","id":"5cb11925d204de785aba91cebea1de7e","attributes":{"id":"5cb11925d204de785aba91cebea1de7e","tags":[],"doc":null,"plot":{"type":"GMapPlot","id":"8dbf065b05f449b6a3e4e3eddd7dab70"}}},{"type":"ColumnDataSource","id":"2d8e42f8b27e1d244555796dbf1eb9e0","attributes":{"id":"2d8e42f8b27e1d244555796dbf1eb9e0","tags":[],"doc":null,"column_names":["x","y"],"selected":[],"discrete_ranges":{},"cont_ranges":{},"data":{"x":[-102.0495,-102.0495,-102.0438,-102.0438,-102.0495,-102.0495,-102.0495,-102.0552,-102.0552,-102.0552,-102.0552,-102.061,-102.0552,null,-102.0495,-102.124,-102.2787,-102.485,-102.7485,-102.886,-103.0063,null,-103.0063,-103.0866,-103.1668,-103.3902,-103.6366,-103.8772,-104.0148,-104.1122,-104.3986,-104.7997,-105.1034,-105.2409,-105.3899,-105.6018,-105.7222,-106.0087,-106.4727,-106.5988,-106.9082,-107.2749,-107.441,-107.4582,-107.5499,-107.9166,-108.2718,-108.3922,-108.4896,-108.6901,-108.9193,-109.0396,null,-109.0511,-109.0568,-109.0568,-109.0568,-109.0625,-109.0568,-109.0568,-109.0511,-109.0453,-109.0511,-109.0396,null,-104.0606,-104.9429,-105.2867,-106.2092,-106.2035,-106.3295,-106.8566,-107.3093,-107.9223,-109.0568,-109.0511,null,-104.0606,-103.5736,-103.373,-102.6568,-102.6167,-102.061,-102.061,-102.0667,-102.061,-102.0667,-102.0667,-102.0552],"y":[37.0016,37.3855,37.6491,37.735,38.2564,38.6116,38.6918,39.0528,39.133,39.5685,39.5799,40.0039,40.0096,null,37.0016,36.9844,36.9844,36.9844,36.9844,36.9844,37.0016,null,37.0016,36.9959,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9844,36.9959,36.9844,36.9959,36.9959,36.9959,36.9959,36.9959,37.0016,36.9959,36.9959,36.9959,null,40.9951,40.6571,40.2216,39.6544,39.4997,39.3622,38.5085,38.1533,37.8668,37.6319,36.9959,null,41.0066,41.0123,41.0066,41.0123,41.0066,41.0066,41.0123,41.018,41.018,40.9894,40.9951,null,41.0066,41.0066,41.0066,41.0066,41.0066,41.0009,40.7488,40.7029,40.6915,40.4394,40.3477,40.0096]}}},{"type":"Line","id":"8e6a27da5eb7a10410d8a65fbaabe4dd","attributes":{"id":"8e6a27da5eb7a10410d8a65fbaabe4dd","tags":[],"doc":null,"group":null,"line_width":{"units":"data","value":2},"line_color":{"units":"data","value":"black"},"line_alpha":{"units":"data","value":1},"x":{"units":"data","field":"x"},"y":{"units":"data","field":"y"}}},{"type":"Line","id":"a7701f1322a37a287ed0bd19c5a67bd3","attributes":{"id":"a7701f1322a37a287ed0bd19c5a67bd3","tags":[],"doc":null,"group":null,"line_width":{"units":"data","value":2},"line_color":{"units":"data","value":"#e1e1e1"},"line_alpha":{"units":"data","value":1},"x":{"units":"data","field":"x"},"y":{"units":"data","field":"y"}}},{"type":"GlyphRenderer","id":"142b82f7d09cd4f539257060e912af31","attributes":{"id":"142b82f7d09cd4f539257060e912af31","tags":[],"doc":null,"selection_glyph":null,"nonselection_glyph":{"type":"Line","id":"a7701f1322a37a287ed0bd19c5a67bd3"},"server_data_source":null,"name":null,"data_source":{"type":"ColumnDataSource","id":"2d8e42f8b27e1d244555796dbf1eb9e0"},"glyph":{"type":"Line","id":"8e6a27da5eb7a10410d8a65fbaabe4dd"}}},{"type":"Range1d","id":"29708b6135c31d54d095eab825018b27","attributes":{"id":"29708b6135c31d54d095eab825018b27","tags":[],"doc":null,"start":-119.427,"end":49.3657}},{"type":"Range1d","id":"bc22d0ee625cab3cf1182c59d13b8b60","attributes":{"id":"bc22d0ee625cab3cf1182c59d13b8b60","tags":[],"doc":null,"start":-115.8131,"end":51.278}},{"type":"LinearAxis","id":"de9180cfd33e41402c266a85d37c1bfb","attributes":{"id":"de9180cfd33e41402c266a85d37c1bfb","tags":[],"doc":null,"plot":{"type":"GMapPlot","id":"8dbf065b05f449b6a3e4e3eddd7dab70"},"axis_label":"","formatter":{"type":"BasicTickFormatter","id":"3bd85cf03424b99ec8bf3624c02c5b20"},"ticker":{"type":"BasicTicker","id":"e84d3d1e21795633a5931f881ae3132f"},"visible":true,"axis_label_text_font_size":"12pt"}},{"type":"BasicTickFormatter","id":"3bd85cf03424b99ec8bf3624c02c5b20","attributes":{"id":"3bd85cf03424b99ec8bf3624c02c5b20","tags":[],"doc":null}},{"type":"BasicTicker","id":"e84d3d1e21795633a5931f881ae3132f","attributes":{"id":"e84d3d1e21795633a5931f881ae3132f","tags":[],"doc":null,"num_minor_ticks":5}},{"type":"LinearAxis","id":"c1b9a7c921e6162b62c8294341550293","attributes":{"id":"c1b9a7c921e6162b62c8294341550293","tags":[],"doc":null,"plot":{"type":"GMapPlot","id":"8dbf065b05f449b6a3e4e3eddd7dab70"},"axis_label":"","formatter":{"type":"BasicTickFormatter","id":"1d4bbe0f4e5143a35b218ea91b955ad6"},"ticker":{"type":"BasicTicker","id":"d5564f3d5b8f3b3148ae77c08b8545ad"},"visible":true,"axis_label_text_font_size":"12pt"}},{"type":"BasicTickFormatter","id":"1d4bbe0f4e5143a35b218ea91b955ad6","attributes":{"id":"1d4bbe0f4e5143a35b218ea91b955ad6","tags":[],"doc":null}},{"type":"BasicTicker","id":"d5564f3d5b8f3b3148ae77c08b8545ad","attributes":{"id":"d5564f3d5b8f3b3148ae77c08b8545ad","tags":[],"doc":null,"num_minor_ticks":5}}];
Bokeh.load_models(all_models);
var model = Bokeh.Collections(modeltype).get(modelid);
var view = new model.default_view({model: model, el: '#8fc67c13aca2ec13a3051c9d728d2bb1'});
Bokeh.index[modelid] = view;
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment