<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/shiny-and-leaflet-for-visualization-awards/"></div></div><div><a data-url="https://www.r-bloggers.com/shiny-and-leaflet-for-visualization-awards/" data-counturl="https://www.r-bloggers.com/shiny-and-leaflet-for-visualization-awards/" data-count="horizontal" data-text="Shiny and Leaflet for Visualization Awards" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://biologyforfun.wordpress.com/2016/09/04/shiny-and-leaflet-for-visualization-awards/"> R – biologyforfun</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Next week will be the <a target="_blank" href="http://gfoe-2016.de/">meeting of the German (and Swiss and Austrians) ecologists</a> in Marburg and the organizing team launched a visualization contest based on spatial data of the stores present in the city. <a target="_blank" href="http://toek.wzw.tum.de/index.php?id=106">Nadja</a> <a target="_blank" href="https://twitter.com/Tritotanus">Simons</a> and I decided to enter the contest, our idea was to link the store data to the city bus network promoting a sustainable and safe way of movement through the town (we are ecologists after all).</p>
<p>We used <a target="_blank" href="https://cran.r-project.org/web/packages/leaflet/index.html">leaflet</a> to prepare the map and plot the bus lines, bus stops and stores. On top of that because all this information is rather overwhelming to grasp (more than 200 stores and 50 bus stops), we implemented a <a target="_blank" href="https://cran.r-project.org/web/packages/shiny/index.html">shiny</a> App to allow the user to restrict its search of the best Bars in Marburg.</p>
<p>All the code is on <a target="_blank" href="https://github.com/Lionel68/VizAward/">GitHub </a>and the App can accessed by clicking <a target="_blank" href="https://gfoe2016.shinyapps.io/VizAward_HS/">here</a>.</p>
<p>Go there, enjoy, and if you want to learn a bit about the process of developing the App come back here.</p>
<p> </p>
<p>First a few words on what is so cool about leaflet:</p>
<ul>
<li>There is a <a target="_blank" href="http://leaflet-extras.github.io/leaflet-providers/preview/index.html">lot of maps</a> available</li>
<li>With the AwesomeMarker plugin, available in the github repo of the package, you can directly tap into three awesome libraries for icons: <a target="_blank" href="http://fontawesome.io/icons/">font awesome</a>, <a target="_blank" href="http://getbootstrap.com/components/#glyphicons">glyphicons</a> and <a target="_blank" href="http://ionicons.com/">ionicons</a></li>
<li>Leaflet understand HTML code, we used it to provide a clickable link to the bus timetables</li>
<li>Using groups makes it easy to interactively add or remove group of objects from the map</li>
</ul>
<p>Having this was already nice, but putting it into a shiny App was even more exciting. Here are some of the main points:</p>
<ul>
<li>A very important concept in shiny is the concept of <a target="_blank" href="http://shiny.rstudio.com/articles/reactivity-overview.html">reactivity</a>, the way I understood it is that a reactive object is a small function that will get updated every time the user input some elements, see <a target="_blank" href="https://uasnap.shinyapps.io/ex_leaflet/">this</a> nice tutorial for more on this.</li>
<li>Our idea of the App was that stores should appear when the mouse is passed over their nearest bus stop. The issue there is that the stores must then disappear if the mouse moves out. The trick is to create a set of reactiveValues that are NULL as long as the event (mouse passes over a bus stop) does not occure AND return to NULL when the event is finished (mouse moves out), helped by <a target="_blank" href="http://stackoverflow.com/questions/35266730/r-leaflet-cran-how-to-register-clicking-off-a-marker?rq=1">this</a> post, we were able to implement what we wanted.</li>
<li>Shiny gives you a lot of freedom to create and customize the design of the App, what I found very cool was the possibility to have tabs.</li>
</ul>
<p>Be sure to check the <a target="_blank" href="https://rstudio.github.io/leaflet/">leaflet tutorial</a> page, 90% of my questions were answered there, also check out the <a target="_blank" href="http://shiny.rstudio.com/articles/">many articles</a> on shiny.</p>
<p>See you in Marburg if you’ll be around!</p>
<p> </p>
<p>Filed under: <a target="_blank" href="https://biologyforfun.wordpress.com/category/biological-stuff/">Biological Stuff</a> Tagged: <a target="_blank" href="https://biologyforfun.wordpress.com/tag/ecology/">ecology</a>, <a target="_blank" href="https://biologyforfun.wordpress.com/tag/r/">R</a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/biologyforfun.wordpress.com/872/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/biologyforfun.wordpress.com/872/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/biologyforfun.wordpress.com/872/"><img alt="" src="http://feeds.wordpress.com/1.0/delicious/biologyforfun.wordpress.com/872/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/biologyforfun.wordpress.com/872/"><img alt="" src="http://feeds.wordpress.com/1.0/facebook/biologyforfun.wordpress.com/872/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/biologyforfun.wordpress.com/872/"><img alt="" src="http://feeds.wordpress.com/1.0/twitter/biologyforfun.wordpress.com/872/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/biologyforfun.wordpress.com/872/"><img alt="" src="http://feeds.wordpress.com/1.0/stumble/biologyforfun.wordpress.com/872/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/biologyforfun.wordpress.com/872/"><img alt="" src="http://feeds.wordpress.com/1.0/digg/biologyforfun.wordpress.com/872/" border="0"></a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/biologyforfun.wordpress.com/872/"><img alt="" src="http://feeds.wordpress.com/1.0/reddit/biologyforfun.wordpress.com/872/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/shiny-and-leaflet-for-visualization-awards/"></div></div><div><a data-url="https://www.r-bloggers.com/shiny-and-leaflet-for-visualization-awards/" data-counturl="https://www.r-bloggers.com/shiny-and-leaflet-for-visualization-awards/" data-count="vertical" data-text="Shiny and Leaflet for Visualization Awards" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://biologyforfun.wordpress.com/2016/09/04/shiny-and-leaflet-for-visualization-awards/"> R – biologyforfun</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/-mFfqgqwxEo"></a></div>