SwarmLab's Shiny webapps for teaching collective behavior and swarm intelligence
R is a programming language and software environment mostly known for its exhaustive suite of statistics tools. But it is much more than a Swiss army knife for data analysis. It is also a fantastic environment to develop quickly programs and apps to support your lecture material and create interactive demos for instance.
If you have not followed closely the news in the R community, there have been multiple important developments pushed by a new generation of very active R programmers, in particular by the terrific team behind the RStudio IDE. One of these developments is the creation of ‘Shiny’, a web application framework for R. ‘Shiny’ allows anybody with intermediate R skills – beginners might struggle a bit – to create in a few lines of code a complete web-application entirely written with the R language.
And this changes everything for people like me who like to provide their students with interactive tools to explore questions and manipulate concepts covered during lectures. Using the ‘Shiny’ framework and with minimum effort, I can now create interactive web apps that showcase classic models of collective behaviors and swarm intelligence. The students can then manipulate the parameters of these models using simple sliders and buttons, and observe directly the consequences on the models’ predictions. This is a fantastic way to create interactive assignments to complement the content of a lecture or to prepare the students for the next one.
Once you have created a web application (I strongly recommend using RStudio for this as it makes the process very smooth), you can host them on your own server or deploy them on ShinyApps.io (in one click from within RStudio), a dedicated service provided by the good folks at RStudio. It is free for small apps, which is largely enough for my class for instance. Larger apps that require heavy data processing for instance might require a paid account.
After testing this approach successfully last semester during my class on “Collective Intelligence in Biological Systems” (NJIT BIOL 337), I decided to use it more systematically this year. I started updating the test apps from last semester and building new ones. I will release them little by little throughout the semester as I find the time to work on them, but you can already test out the first 3 of them and download their source code on my GitHub:
Collective food source selection in ants:
Source code: https://github.com/sjmgarnier/Shiny/tree/master/ant_collective_decision
App: http://sjmgarnier.shinyapps.io/ant_collective_decision/
Collective nest selection in honeybees:
Source code: https://github.com/sjmgarnier/Shiny/tree/master/bee_house_hunting
App: http://sjmgarnier.shinyapps.io/bee_house_hunting/
Opinion dynamics (spreading and competition):
Source code: https://github.com/sjmgarnier/Shiny/tree/master/opinion_dynamic
App: http://sjmgarnier.shinyapps.io/opinion_dynamic/
The 3 apps (as well as those that will follow) are distributed under the GPL-3 license. Feel free to download, use, modify and redistribute the source code. Comments and suggestions of new models to include in this list are very welcome!


















