### Install Example Notebook Dependencies Source: https://github.com/voila-dashboards/voila/blob/main/docs/using.md Install necessary Python libraries to run the example notebooks provided with Voilà. This ensures all interactive widgets and functionalities are available. ```bash conda install -c conda-forge ipywidgets ipyvolume bqplot scipy ``` ```bash conda env create ``` -------------------------------- ### Voila Instantiation Command Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Example command line used to start Voila when configured with Apache2 as a reverse proxy, specifying port and base URL. ```text $ voila --autoreload=True --port=50001 --base_url=/voila/ ``` -------------------------------- ### Render ipyvolume Example Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/ipyvolume.ipynb This snippet shows how to import the ipyvolume library and render an example visualization using Voilà. It requires the ipyvolume package to be installed. ```Python import ipyvolume as ipv ipv.examples.example_ylm(); ``` -------------------------------- ### Setup Voilà Development Environment Source: https://github.com/voila-dashboards/voila/blob/main/docs/contribute.md Steps to set up a local development environment for Voilà using conda, git, yarn, and pip. This includes creating a new conda environment, cloning the repository, installing JavaScript dependencies, and installing Voilà in editable mode. ```bash # create a new conda environment conda create -n voila -c conda-forge notebook jupyterlab nodejs "yarn<4" pip conda activate voila # download voila from your GitHub fork git clone https://github.com//voila.git # install JS dependencies and build js assets cd voila yarn install # install Voilà in editable mode python -m pip install -e . ``` -------------------------------- ### Enable and Start Voila Service Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Enable the Voila systemd service to start on boot and then start the service. ```text sudo systemctl enable voila.service sudo systemctl start voila.service ``` -------------------------------- ### Voila Test Setup and Execution Source: https://github.com/voila-dashboards/voila/blob/main/docs/contribute.md Provides the necessary bash commands to install Voila's test dependencies, enable the Jupyter server extension, install specific test templates, and finally execute the test suite using pytest. ```bash python -m pip install -e ".[test]" ``` ```bash jupyter server extension enable voila.server_extension --sys-prefix ``` ```bash python -m pip install ./tests/test_template ./tests/skip_template ``` ```bash python -m pytest ``` -------------------------------- ### Enable and Start Nginx Service Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Enable Nginx to start automatically on boot and then start the service immediately. ```text sudo systemctl enable nginx.service sudo systemctl start nginx.service ``` -------------------------------- ### Install Nginx Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Install the Nginx web server on your system using the apt package manager. ```text sudo apt install nginx ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Install Python dependencies listed in the requirements.txt file using pip. ```text sudo python3 -m pip install -r requirements.txt ``` -------------------------------- ### Install Certbot for Let's Encrypt Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Install Certbot and the Nginx plugin to manage SSL certificates for your domain. ```text sudo add-apt-repository ppa:certbot/certbot sudo apt update sudo apt install python-certbot-nginx ``` -------------------------------- ### Start Voilà and ngrok for Sharing Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Commands to start a Voilà application locally without a browser and expose it to the internet using ngrok. This enables quick sharing of interactive notebooks by forwarding public requests to your local Voilà instance. ```shell voila --no-browser my_notebook.ipynb ``` ```shell ngrok http 8866 ``` -------------------------------- ### Install Python Pip Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Install or update pip, the package installer for Python, using apt. ```text sudo apt update && sudo apt install python3-pip ``` -------------------------------- ### Install JupyterLab Preview Extension Source: https://github.com/voila-dashboards/voila/blob/main/README.md Installs the Voilà JupyterLab extension, which provides a preview of your Notebook within a side-pane in JupyterLab. This command is run from the command line. ```shell jupyter labextension install @voila-dashboards/jupyterlab-preview ``` -------------------------------- ### Install and Enable Voilà Notebook Extension Source: https://github.com/voila-dashboards/voila/blob/main/docs/contribute.md Commands to install and enable the Voilà notebook extension for the classic Jupyter Notebook interface. This ensures Voilà functionality is available within the notebook environment. ```bash jupyter nbextension install voila --sys-prefix --py jupyter nbextension enable voila --sys-prefix --py ``` -------------------------------- ### Install Voilà with Pip Source: https://github.com/voila-dashboards/voila/blob/main/docs/install.md Installs Voilà using the pip package installer from PyPI. This method is suitable for users who prefer or only have pip available. ```bash pip install voila ``` -------------------------------- ### Setup Voilà JupyterLab Extension Source: https://github.com/voila-dashboards/voila/blob/main/docs/contribute.md Instructions for setting up the Voilà JupyterLab extension, which requires Node.js. It involves enabling the server extension, linking the development version, and building the extension. ```bash # Install Node.js if not already present: conda install -c conda-forge nodejs # Enable server extension (required): jupyter serverextension enable voila --sys-prefix # Verify server extension status: jupyter serverextension list # For Jupyter Server: jupyter server extension enable voila --sys-prefix # Link development version and build: python -m pip install -e . jupyter labextension develop . --overwrite jlpm run build --scope @voila-dashboards/jupyterlab-preview # Optional: Start in watch mode for automatic updates: jlpm run watch ``` -------------------------------- ### C++ Standard Library Setup Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/print_cpp.ipynb Includes the iostream library for input/output operations and brings the standard namespace into scope. This is a common setup for C++ console applications. ```c++ #include using namespace std; ``` -------------------------------- ### Python Get Query String Example Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/preheat/get_query_string.ipynb This snippet demonstrates how to retrieve the query string using the `get_query_string` utility function from the Voila library. It imports the function and prints its output. ```python from voila.utils import get_query_string print(get_query_string()) ``` -------------------------------- ### Print Hello World in Python Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/reveal.ipynb A simple Python script that prints the string 'hi' to the console. This is a basic example of standard output. ```python print('hi') ``` -------------------------------- ### Create and Display ipywidgets Output Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/output.ipynb Demonstrates the basic creation of an `ipywidgets.Output` widget and its display. This is the foundational step for capturing and rendering output programmatically within a Jupyter environment. ```python import ipywidgets as widgets output1 = widgets.Output() output1 ``` -------------------------------- ### Build and Lint Frontend Packages Source: https://github.com/voila-dashboards/voila/blob/main/docs/contribute.md Commands for managing frontend packages in the Voilà monorepo. This includes installing dependencies with jlpm, building all packages, and running linters like ESLint and Prettier. ```bash # Install dependencies: jlpm # Build all packages: jlpm run build # Run ESLint: jlpm run eslint # Run Prettier: jlpm run prettier ``` -------------------------------- ### Run Voilà Source: https://github.com/voila-dashboards/voila/blob/main/docs/contribute.md Commands to start the Voilà application. It can be run directly or via the Python module, typically opening a browser tab at http://localhost:8866/. Instructions are also provided for watching frontend changes. ```bash voila ``` ```bash python -m voila ``` ```bash # For frontend changes: cd packages/voila/ npm run watch ``` -------------------------------- ### Adjust Kernel Startup Timeout Source: https://github.com/voila-dashboards/voila/blob/main/docs/customize.md Sets the grace period for kernel startup time in Voilà. If a kernel does not start within this duration, it may be considered failed. ```bash voila --VoilaExecutor.startup_timeout=60 ``` -------------------------------- ### Setup Matplotlib Notebook Backend Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/other_comms.ipynb Configures the matplotlib backend to enable interactive plots within a notebook environment. It imports the necessary pyplot module from matplotlib. ```python %matplotlib notebook import matplotlib.pyplot as plt ``` -------------------------------- ### Render ipywidgets with Voilà Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/interactive.ipynb This snippet demonstrates how to use Voilà to render interactive notebooks that utilize ipywidgets' `@interact` functionality. It sets up sliders and a function to display their product, then renders them using HBox and VBox for interactive display. ```Python from ipywidgets import HBox, VBox, IntSlider, interactive_output from IPython.display import display a = IntSlider() b = IntSlider() def f(a, b): print("{} * {} = {}".format(a, b, a * b)) out = interactive_output(f, { "a": a, "b": b }) display(HBox([VBox([a, b]), out])) ``` -------------------------------- ### Nginx HTTPS Configuration Snippet Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Example of Nginx configuration lines added by Certbot for enabling SSL/TLS on port 443. ```text $ cat /etc/nginx/sites-enabled/yourdomain.com ... listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot ... ``` -------------------------------- ### Voila Systemd Service Configuration Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Create a systemd service file to manage the Voila process. This configuration ensures Voila runs as a specific user, restarts automatically on failure, and starts on system boot. ```systemd [Unit] Description=Voila [Service] Type=simple PIDFile=/run/voila.pid ExecStart=voila --no-browser voila/notebooks/basics.ipynb User=ubuntu WorkingDirectory=/home/ubuntu/ Restart=always RestartSec=10 [Install] WantedBy=multi-user.target ``` -------------------------------- ### Redirect Print Output to Widget Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/output.ipynb Shows how to capture standard print statements within a context manager (`with output_widget:`). The output is then directed to the specified `ipywidgets.Output` widget, allowing for dynamic display of information. ```python print("hi") with output1: print("in output") ``` ```python print("hi2") with output2: print("in output2") ``` ```python print("hi3") with output3: print("hello") print("world") ``` ```python print("hi4") with output4: print("hello world") ``` -------------------------------- ### Displaying Images Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/mimerenderers.ipynb Loads and displays an image from a URL using the IPython.display.Image class. The example uses an image of the Milky Way from NASA's APOD. ```python img = Image("https://apod.nasa.gov/apod/image/1707/GreatWallMilkyWay_Yu_1686.jpg") img ``` -------------------------------- ### Nested Output Widgets Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/output.ipynb Shows how to create and display nested `ipywidgets.Output` widgets. This allows for hierarchical organization of output within a dashboard, where inner outputs are contained within outer ones. ```python output_outer = widgets.Output() output_inner = widgets.Output() output_inner ``` ```python output_outer ``` -------------------------------- ### Python: Sleep and Print Example Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/preheat/pre_heat.ipynb Demonstrates basic Python execution with a time delay and printing to the console. This snippet utilizes the built-in `time` module for pausing execution and standard output. ```python import time time.sleep(2) print('hello world') ``` -------------------------------- ### Python: Sleep and Print Example Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/preheat/default_env_variables.ipynb Demonstrates pausing execution using `time.sleep` and printing output to the console. This snippet is useful for basic script timing and output verification. It has no external dependencies beyond the standard Python library. ```python import time time.sleep(2) print('hello world') ``` -------------------------------- ### Python: Sleep and Print Example Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/preheat/denylisted.ipynb Demonstrates basic Python execution with a time delay and printing to the console. This snippet utilizes the built-in `time` module for pausing execution and standard output. ```python import time time.sleep(2) print('hello world') ``` -------------------------------- ### C++ Kernel Setup and Includes Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/xleaflet.ipynb Sets up the C++ environment for Voilà integration, including essential headers for standard I/O, strings, xwidgets, and xleaflet components. It also establishes the namespace for nlohmann JSON, commonly used for configuration. ```C++ #include #include #include "xwidgets/xoutput.hpp" #include "xleaflet/xmap.hpp" #include "xleaflet/xdraw_control.hpp" #include "xleaflet/xbasemaps.hpp" namespace nl = nlohmann; ``` -------------------------------- ### Clone Voilà Repository and Navigate Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Clones the Voilà GitHub repository and navigates into the notebooks directory. This sets up the project structure for deployment. ```bash git clone git@github.com:voila-dashboards/voila.git cd voila/notebooks/ ``` -------------------------------- ### Install Voilà with Mamba/Conda Source: https://github.com/voila-dashboards/voila/blob/main/docs/install.md Installs Voilà using the Mamba or Conda package manager from the conda-forge channel. This is the recommended method for users with Mamba or Conda installed. ```bash mamba install -c conda-forge voila ``` -------------------------------- ### Install Voilà with Pip Source: https://github.com/voila-dashboards/voila/blob/main/README.md Installs the Voilà package using pip, the standard Python package installer. This command fetches Voilà from the Python Package Index (PyPI). ```shell pip install voila ``` -------------------------------- ### Install Voilà with Mamba Source: https://github.com/voila-dashboards/voila/blob/main/README.md Installs the Voilà package using the mamba package manager from the conda-forge channel. This is a recommended method for managing Python environments and dependencies. ```shell mamba install -c conda-forge voila ``` -------------------------------- ### Basic Python Sleep and Print Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/sleep10seconds.ipynb This script imports the time module to pause execution for a specified duration and then uses the print function to display a message to the console. It's a fundamental example of sequential execution and time-based operations in Python. ```python import time time.sleep(10) print("Hi") ``` -------------------------------- ### Check Nginx Status Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Verify that the Nginx service is running correctly after installation. ```text sudo systemctl status nginx ``` -------------------------------- ### Initialize Leaflet Map Widget Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/xleaflet.ipynb Demonstrates the initialization of an interactive Leaflet map widget using the xleaflet library. This snippet configures the basemap, sets the initial center coordinates and zoom level, and finalizes the map object for display. ```C++ // Create map widget auto water_color = xlf::basemap({"OpenStreetMap", "France"}); auto map = xlf::map::initialize() .layers({water_color}) .center({47, 363}) .zoom(5) .finalize(); map ``` -------------------------------- ### Google App Engine CLI Commands Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Commands to deploy your application to Google App Engine and browse the deployed application. ```bash gcloud app deploy ``` ```bash gcloud app browse ``` -------------------------------- ### Get Query String (Normal Mode) Source: https://github.com/voila-dashboards/voila/blob/main/docs/customize.md Demonstrates how to access the URL query string in normal Voilà execution using the `QUERY_STRING` environment variable. ```python import os query_string = os.getenv('QUERY_STRING') ``` -------------------------------- ### Enable Voilà Server Extension Source: https://github.com/voila-dashboards/voila/blob/main/docs/contribute.md Commands to enable the Voilà server extension for both classic notebook and Jupyter Server. This makes Voilà accessible via a specific URL. ```bash # For classic notebook server extension: jupyter serverextension enable voila --sys-prefix ``` ```bash # For Jupyter Server: jupyter server extension enable voila.server_extension --sys-prefix ``` -------------------------------- ### Configure WebSocket Settings via Command Line Source: https://github.com/voila-dashboards/voila/blob/main/docs/customize.md Shows how to set WebSocket protocol and IP address using command-line arguments for Voilà, overriding default or configuration file settings. ```bash voila --preheat_kernel=True --VoilaKernelManager.default_env_variables='{"VOILA_WS_PROTOCOL":"wss","VOILA_APP_IP":"192.168.1.1"}' ``` -------------------------------- ### Suppress Python Warnings Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/bqplot.ipynb This Python snippet suppresses warning messages, which can be useful for cleaning up output during notebook execution. It uses the built-in `warnings` module. ```python import warnings warnings.filterwarnings('ignore') ``` -------------------------------- ### Apache2 Reverse Proxy Configuration Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Configure Apache2 as a reverse proxy for Voila, including proxying WebSocket connections. This example shows a VirtualHost configuration for HTTPS. ```apache # ... ProxyRequests Off ProxyPreserveHost Off RewriteEngine on RewriteCond %{REQUEST_URI} /voila/api/kernels/ RewriteRule .*/voila/(.*) "ws://127.0.0.1:50001/voila/$1" [P,L] ProxyPreserveHost On ProxyPass http://127.0.0.1:50001/voila/ ProxyPassReverse http://127.0.0.1:50001/voila/ ``` -------------------------------- ### Initialize ipywidgets Label Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/dashboard.ipynb Creates an ipywidgets Label to display selected information. This widget will be updated dynamically based on user interaction. ```python import ipywidgets as widgets label_selected = widgets.Label(value="Selected: 0") label_selected ``` -------------------------------- ### Running Voilà with a Custom Template Source: https://github.com/voila-dashboards/voila/blob/main/docs/customize.md Shows the command-line usage for launching Voilà with a specific custom template. The `--template` argument points to the name of the template folder containing your customizations. ```bash voila mynotebook.ipynb --template=mytemplate ``` -------------------------------- ### Print Message in Python Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/no_kernelspec.ipynb This Python snippet demonstrates printing a message to the console. It's a basic example that executes a print statement without requiring a specific kernelspec. ```python print('Executing without a kernelspec') ``` -------------------------------- ### Show Bokeh App with Voila URL Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/bokeh.ipynb Demonstrates how to display the Bokeh application within Voila by passing the Voila server URL to the `show` method. This ensures correct rendering in the Voila environment by constructing the `notebook_url` from environment variables. ```python from urllib.parse import urlparse url = urlparse(os.environ.get("VOILA_REQUEST_URL")) show(bkapp, notebook_url=f"{url.scheme}://{url.netloc}") ``` -------------------------------- ### Displaying SVG Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/mimerenderers.ipynb Renders Scalable Vector Graphics (SVG) content using the IPython.display.SVG class. The example defines a simple SVG rectangle. ```python svg_source = """ """ svg = SVG(svg_source) svg ``` -------------------------------- ### Railway Deployment Configuration Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md Configuration files for deploying Voilà dashboards on Railway. runtime.txt specifies the Python version, and Procfile defines the web server command to run Voilà. ```text python-3.10.4 ``` ```text web: voila --port=$PORT --no-browser --Voila.ip=0.0.0.0 ``` ```text web: voila --port=$PORT --no-browser --Voila.ip=0.0.0.0 your_notebook.ipynb ``` -------------------------------- ### Python String Concatenation Source: https://github.com/voila-dashboards/voila/blob/main/tests/notebooks/syntax_error.ipynb Demonstrates basic string concatenation in Python. This code joins two string literals and prints the result. It's a fundamental example of string manipulation. ```python print('This should ' + 'not be executed') ``` -------------------------------- ### Customizing Voilà Configuration on Binder Source: https://github.com/voila-dashboards/voila/blob/main/docs/deploy.md A JSON configuration file to customize Voilà's behavior, such as setting the theme and template. This file should be placed at the root of the repository. ```json { "VoilaConfiguration": { "theme": "dark", "template": "gridstack" } } ``` -------------------------------- ### NumPy Initialization Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/dashboard.ipynb Initializes NumPy arrays for data generation. Sets up a sequence of numbers and cumulative random values for plotting. ```python import numpy as np n = 200 x = np.linspace(0.0, 10.0, n) y = np.cumsum(np.random.randn(n)*10).astype(int) ``` -------------------------------- ### Construct and Display Web Link Source: https://github.com/voila-dashboards/voila/blob/main/notebooks/query-strings.ipynb Constructs a URL based on environment variables like 'SERVER_NAME', 'SERVER_PORT', and 'SCRIPT_NAME'. It then generates an HTML anchor tag with a link that includes a 'username' query parameter, displaying it using IPython.display.HTML. ```python server = os.environ.get('SERVER_NAME', 'localhost') url = "http://" + server port = os.environ.get('SERVER_PORT', '') if port: url += ":" + port path = os.environ.get('SCRIPT_NAME', '') url += path IPython.display.HTML(data=f""" Link to myself as user Riley """) ``` -------------------------------- ### Set Default Environment Variables via CLI Source: https://github.com/voila-dashboards/voila/blob/main/docs/customize.md Activates the preheated kernel feature and sets default environment variables for all preheated kernels. This example sets the environment variable 'FOO' to 'BAR'. ```bash voila --preheat_kernel=True --VoilaKernelManager.default_env_variables='{"FOO": "BAR"}' ```