<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Jupyter Blog - Marianne Corvellec</title><link href="https://jasongrout.github.io/medium-archive/pelican/" rel="alternate"/><link href="https://jasongrout.github.io/medium-archive/pelican/feeds/author-marianne-corvellec.atom.xml" rel="self"/><id>https://jasongrout.github.io/medium-archive/pelican/</id><updated>2019-10-29T14:11:00+00:00</updated><subtitle>The Project Jupyter blog: news, releases, and community stories, archived from blog.jupyter.org.</subtitle><entry><title>A slideshow template for Voilà apps</title><link href="https://jasongrout.github.io/medium-archive/pelican/posts/2019/a-slideshow-template-for-voila-apps/" rel="alternate"/><published>2019-10-29T10:32:00+00:00</published><updated>2019-10-29T14:11:00+00:00</updated><author><name>Marianne Corvellec</name></author><id>tag:jasongrout.github.io,2019-10-29:/medium-archive/pelican/posts/2019/a-slideshow-template-for-voila-apps/</id><summary type="html">&lt;p&gt;Voilà can now serve your interactive dashboards in a slideshow format.&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Last June, QuantStack &lt;a href="/posts/2019/and-voila/"&gt;announced&lt;/a&gt; the first release of &lt;a href="https://github.com/voila-dashboards/voila"&gt;Voilà&lt;/a&gt;, a solution to turn Jupyter notebooks into &lt;em&gt;standalone web applications&lt;/em&gt;. Voilà enforces &lt;em&gt;security&lt;/em&gt; (preventing arbitrary code execution) while preserving &lt;em&gt;interactivity&lt;/em&gt; (supporting interactive widgets for Jupyter notebooks, including roundtrips to the kernel). A recent addition to the ever-teeming &lt;a href="https://jupyter.org"&gt;Jupyter&lt;/a&gt; ecosystem, Voilà is flexible, extensible, and language-agnostic (running any Jupyter kernel, such as Python, R, Julia, C++).&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Voilà logo." src="https://jasongrout.github.io/medium-archive/pelican/posts/2019/a-slideshow-template-for-voila-apps/images/001-1_JLepfTuigc_h1Gfy768BWg.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;A dashboarding solution based on Jupyter.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="getting-started-with-voila"&gt;Getting started with Voilà&lt;/h2&gt;
&lt;p&gt;Voilà is available as a Python package on &lt;a href="https://github.com/conda-forge/voila-feedstock"&gt;conda-forge&lt;/a&gt; and &lt;a href="https://pypi.org/project/voila"&gt;PyPI&lt;/a&gt;. After installing Voilà in their environment, Jupyter notebook users will see a new button in the toolbar, a button reading “Voila” with a display icon. Clicking this button will take you to a Voilà web app served &lt;a href="https://voila.readthedocs.io/en/stable/using.html#as-a-jupyter-server-extension"&gt;with the notebook server&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Screenshot of Jupyter notebook interface showing Voila button in toolbar." src="https://jasongrout.github.io/medium-archive/pelican/posts/2019/a-slideshow-template-for-voila-apps/images/002-1_rQ6byMkg3MIOpOS0dvWOig.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Voilà use case as a Jupyter server extension.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Alternatively, you can use Voilà to create a standalone &lt;a href="https://www.tornadoweb.org"&gt;Tornado&lt;/a&gt; application. From the terminal, run &lt;code&gt;$ voila index.ipynb&lt;/code&gt; to turn notebook &lt;code&gt;index.ipynb&lt;/code&gt; into a web app. Note that you don’t launch nor run the Jupyter notebook yourself. At this point, Voilà serves the app locally.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Screencast of Voilà app (default template)." src="https://jasongrout.github.io/medium-archive/pelican/posts/2019/a-slideshow-template-for-voila-apps/images/003-1_x-8g5Ux5j4wPmwI5TYSWkw.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Jupyter notebook turned Voilà app (&lt;a href="https://github.com/mkcor/voila-reveal-example"&gt;source&lt;/a&gt;).&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Of course, the full value of sharing these apps (typically analytics web apps, data dashboards) comes from &lt;em&gt;deploying&lt;/em&gt; them. Voilà apps can come into play at different steps of a data science workflow, from the initial step of &lt;em&gt;exploring data&lt;/em&gt; all the way to the final step of &lt;em&gt;communicating results&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id="styling-voila-apps-with-layout-templates"&gt;Styling Voilà apps with layout templates&lt;/h2&gt;
&lt;p&gt;Now, you may want to customize the &lt;em&gt;layout&lt;/em&gt; of your app, especially if it is somewhat complex. For example, you can make results more readable by splitting them and using different tab panes or boxes. This you can already achieve with the &lt;code&gt;voila-gridstack&lt;/code&gt; template, also available from either &lt;a href="https://github.com/conda-forge/voila-gridstack-feedstock"&gt;conda-forge&lt;/a&gt; or &lt;a href="https://pypi.org/project/voila-gridstack"&gt;PyPI&lt;/a&gt; (still in beta).&lt;/p&gt;
&lt;p&gt;Templates are written in &lt;a href="https://jinja.palletsprojects.com"&gt;Jinja&lt;/a&gt; and use the &lt;code&gt;metadata&lt;/code&gt; field of the notebook cells. Practically, a Voilà template is a folder which lives under &lt;code&gt;PREFIX/share/jupyter/voila/templates/&lt;/code&gt;. The system of &lt;em&gt;custom templates&lt;/em&gt; is actually where the &lt;em&gt;extensibility&lt;/em&gt; of Voilà shines most. Here, we introduce &lt;a href="https://github.com/voila-dashboards/voila-reveal"&gt;voila-reveal&lt;/a&gt;, a &lt;em&gt;slideshow&lt;/em&gt; template for Voilà. It builds off of &lt;a href="https://github.com/damianavila/RISE"&gt;RISE&lt;/a&gt;, which itself builds off of &lt;a href="http://lab.hakim.se/reveal-js"&gt;reveal.js&lt;/a&gt;. The credit goes to Maarten Breddels for initiating development a few months ago.&lt;/p&gt;
&lt;h2 id="rendering-voila-apps-as-slideshows"&gt;Rendering Voilà apps as slideshows&lt;/h2&gt;
&lt;p&gt;With RISE, you can instantly turn your Jupyter notebook into a slideshow. Besides, if you share it within a &lt;a href="https://mybinder.readthedocs.io/en/latest/introduction.html#what-is-a-binder"&gt;binder&lt;/a&gt;, collaborators can readily view it in their web browser, with no need for a local setup. They can enjoy the interactive controls, if any. They are expected to run code though (&lt;a href="https://mybinder.org/v2/gh/damianavila/RISE/master?filepath=examples%2FREADME.ipynb"&gt;example&lt;/a&gt;), which may not be suitable if they are non-technical. And, even if they are, you may want to prevent arbitrary code execution.&lt;/p&gt;
&lt;p&gt;With Voilà and its new &lt;code&gt;reveal&lt;/code&gt; template, you can achieve this by sharing your RISE slideshow as a standalone web application. How so? Ever since &lt;a href="https://medium.com/@mjspeck/presenting-code-using-jupyter-notebook-slides-a8a3c3b59d67"&gt;Jupyter notebook slides&lt;/a&gt;, it has been possible to author or edit a Jupyter notebook with slideshow-related information on each cell. In principle, we could also add (or edit) these cell metadata manually (or automatically) by post-processing the JSON.&lt;/p&gt;
&lt;p&gt;Our custom slideshow template &lt;code&gt;voila-reveal&lt;/code&gt; leverages these very cell metadata (namely, subfield &lt;code&gt;slideshow&lt;/code&gt; of field &lt;code&gt;metadata&lt;/code&gt;). It handles them the exact same way &lt;a href="https://github.com/jupyter/nbconvert/blob/cda5ec4bd062a9ba01a799575942d87a509a771f/nbconvert/exporters/slides.py"&gt;nbconvert&lt;/a&gt; does when generating slideshow HTML from a notebook. It also passes default values to specific resources required by &lt;code&gt;reveal&lt;/code&gt;. These &lt;code&gt;reveal&lt;/code&gt;-required resources are: &lt;code&gt;scroll&lt;/code&gt;, &lt;code&gt;theme&lt;/code&gt;, and &lt;code&gt;transition&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To use the slideshow template with Voilà, install the &lt;code&gt;voila-reveal&lt;/code&gt; package: &lt;code&gt;$ conda install voila-reveal&lt;/code&gt; or &lt;code&gt;$ pip install voila-reveal&lt;/code&gt;. This will create and populate the &lt;code&gt;PREFIX/share/jupyter/voila/templates/reveal/&lt;/code&gt; folder. At the command line, serve the &lt;code&gt;index.ipynb&lt;/code&gt; notebook as a standalone app with the following command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;$&lt;span class="w"&gt; &lt;/span&gt;voila&lt;span class="w"&gt; &lt;/span&gt;index.ipynb&lt;span class="w"&gt; &lt;/span&gt;--template&lt;span class="o"&gt;=&lt;/span&gt;reveal
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;… and voilà!&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Screencast of Voilà app in slideshow format showing zoom transition (configured)." src="https://jasongrout.github.io/medium-archive/pelican/posts/2019/a-slideshow-template-for-voila-apps/images/004-1_Pg6UNndYe0TIfRIeXy3RvA.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Voilà app rendered as a slideshow with slide transitions configured to zoom in and out (&lt;a href="https://github.com/mkcor/voila-reveal-example"&gt;source&lt;/a&gt;).&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="configuring-templates-at-the-command-line"&gt;Configuring templates at the command line&lt;/h2&gt;
&lt;p&gt;You can overwrite the above-mentioned resource defaults by passing additional options. For instance, the default value of &lt;code&gt;transition&lt;/code&gt; is &lt;code&gt;&amp;quot;fade&amp;quot;&lt;/code&gt;. To get the &lt;code&gt;&amp;quot;zoom&amp;quot;&lt;/code&gt; behaviour, we could use the following command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;$&lt;span class="w"&gt; &lt;/span&gt;voila&lt;span class="w"&gt; &lt;/span&gt;index.ipynb&lt;span class="w"&gt; &lt;/span&gt;--template&lt;span class="o"&gt;=&lt;/span&gt;reveal&lt;span class="w"&gt; &lt;/span&gt;--VoilaConfiguration.resources&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;{&amp;#39;reveal&amp;#39;: {&amp;#39;transition&amp;#39;: &amp;#39;zoom&amp;#39;}}&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Admittedly, it is verbose and cumbersome. Another possibility is to specify (here, &lt;code&gt;reveal&lt;/code&gt;-specific) resources in a &lt;em&gt;configuration file&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id="configuring-templates-with-a-json-file"&gt;Configuring templates with a JSON file&lt;/h2&gt;
&lt;p&gt;Write your configuration file, named &lt;code&gt;conf.json&lt;/code&gt;, with the following structure:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;traitlet_configuration&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;resources&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;reveal&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;scroll&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;theme&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;simple&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;transition&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;zoom&amp;quot;&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then, it is enough to run &lt;code&gt;$ voila index.ipynb --template=reveal&lt;/code&gt; to get slide transitions zoomed in and out; Voilà picks up the config file, as long as it lives under &lt;code&gt;PREFIX/share/jupyter/voila/templates/reveal/&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In the above &lt;a href="https://github.com/mkcor/voila-reveal-example"&gt;demo&lt;/a&gt; screencast, we showcase a scatter plot and a scatter matrix of the “iris” dataset made with &lt;a href="https://plot.ly/python/plotly-express"&gt;Plotly Express&lt;/a&gt; and customizable with &lt;a href="https://ipywidgets.readthedocs.io"&gt;ipywidgets&lt;/a&gt; dropdowns. To display the Python code for these plots, run&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;$&lt;span class="w"&gt; &lt;/span&gt;voila&lt;span class="w"&gt; &lt;/span&gt;index.ipynb&lt;span class="w"&gt; &lt;/span&gt;--template&lt;span class="o"&gt;=&lt;/span&gt;reveal&lt;span class="w"&gt; &lt;/span&gt;--strip_sources&lt;span class="o"&gt;=&lt;/span&gt;False
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To turn on scrollbars, so you can view the plots entirely, run&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;$&lt;span class="w"&gt; &lt;/span&gt;voila&lt;span class="w"&gt; &lt;/span&gt;index.ipynb&lt;span class="w"&gt; &lt;/span&gt;--template&lt;span class="o"&gt;=&lt;/span&gt;reveal&lt;span class="w"&gt; &lt;/span&gt;--strip_sources&lt;span class="o"&gt;=&lt;/span&gt;False&lt;span class="w"&gt; &lt;/span&gt;--VoilaConfiguration.resources&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;{&amp;#39;reveal&amp;#39;: {&amp;#39;scroll&amp;#39;: True}}&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;or edit the &lt;code&gt;scroll&lt;/code&gt; value in the configuration file!&lt;/p&gt;
&lt;h2 id="coming-next"&gt;Coming next&lt;/h2&gt;
&lt;p&gt;At the moment, you must specify the template upon launching Voilà. We would like to be able to toggle between different templates on the fly (without restarting the app). To this end, we shall support template specification as a URL parameter. We shall make &lt;em&gt;template selection&lt;/em&gt; available from the Jupyter interface as well.&lt;/p&gt;
&lt;h2 id="acknowledgments"&gt;Acknowledgments&lt;/h2&gt;
&lt;p&gt;The development of &lt;code&gt;voila-reveal&lt;/code&gt; is entirely supported by &lt;a href="https://github.com/QuantStack"&gt;QuantStack&lt;/a&gt;. The author would like to thank Jeremy Tuloup, Johan Mabille, and Sylvain Corlay for their valuable feedback on this piece.&lt;/p&gt;
&lt;h2 id="about-the-author"&gt;About the author&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://github.com/mkcor"&gt;Marianne Corvellec&lt;/a&gt; is an independent scientific software developer. She is also an independent researcher affiliated with &lt;a href="https://igdore.org"&gt;IGDORE&lt;/a&gt;. She holds a PhD in statistical physics from Ecole Normale Supérieure de Lyon, France.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jasongrout.github.io/medium-archive/pelican/posts/2019/a-slideshow-template-for-voila-apps/images/005-1_ZrMs1GjNdEYhsbqese6xVA.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
</content><category term="dashboards"/><category term="Voilà"/></entry></feed>