{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Formula widget\n", "\n", "Formula widgets calculate aggregated values (`Avg`, `Max`, `Min`, `Sum`) from numeric columns or counts of features (`Count`) in a dataset. A formula widget's aggregations can be calculated on `global` or `viewport` based values. If you want the values in a formula widget to update on zoom and/or pan, use viewport based aggregations. \n", "\n", "To see available parameters run `help(formula_widget)`.\n", "\n", "In this example, the formula widget displays the _sum_ of people involved in the map's current viewport. Since the calculations are viewport based (the default), the count of collisions will update any time the map is zoomed or panned." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from cartoframes.auth import set_default_credentials\n", "\n", "set_default_credentials('cartoframes')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " None\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " Static map image\n", " \n", " \n", " \n", "\n", "\n", " \n", "
\n", "
\n", "
\n", " \n", " \n", "
\n", "
\n", "
\n", "\n", " \n", "\n", "
\n", "
\n", " :\n", "
\n", " \n", " \n", "
\n", "
\n", "\n", "
\n", " StackTrace\n", "
    \n", "
    \n", "
    \n", "\n", "\n", "\n", "\n", "\n", "\">\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes.viz import Layer, formula_widget\n", "\n", "Layer(\n", " 'seattle_collisions',\n", " widgets=[\n", " formula_widget(\n", " 'personcount',\n", " operation='sum',\n", " title='Number of people Involved',\n", " description='Zoom and/or pan the map to update count',\n", " format='.3s'\n", " )\n", " ]\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 2 }