"Then we can add the components we want to the app layout, each component works like a HTML element to which we can set a CSS style attribute to manage its size, color, font, etc...\n",
"We will now use the Dash_Leaflet Library to display an interactive map, the component to use is ```dl.Map()``` , without adding anything else, the only thing that will be displayed is a grey square, we need to draw some map tiles. By adding ``` dl.TileLayer()``` as an argument, Dash Leaflet will add a basic map layer.\n",
"We will now use the Dash_Leaflet Library to display an interactive map, the component to use is ```dl.Map()``` , without adding anything else, the only thing that will be displayed is a grey square, we need to draw some map tiles. By adding ``` dl.TileLayer()``` as an argument, Dash Leaflet will add a default map layer based on OpenStreetMap.\n",
"Now that we have our map, let's see what we can do with it. \n",
"\n",
"The ```children``` attribute of the map component allows us to add different kinds of layers to the map.\n",
"\n",
"Markers : \n",
"The ```children``` attribute of the map component allows us to add different kinds of layers to the map such as markers, polygons, and many others.\n",
"\n",
"```Python\n",
"marker = dl.Marker(position = [46.5,2.25])\n",
"marker = dl.Marker(position = [46.5,2.25], id ='marker')\n",
"A Dash callback is made of 2 parts : A function that will be called when a specified component is updated, and a function decorator which will define the inputs : the variables the app is gonna watch for updates, and the output : the component that's gonna be changed when the function is called. \n",
"This decorator means the app will be looking for any updates to the number of times the marker has been clicked, and that the result of the following function will be sent to the component with the 'result' id.\n",
"\n",
"```Python\n",
"def print_click(n):\n",
" return str(n)\n",
"``` \n",
"\n",
"The print_click function will be called every time the app detects an update on the 'n_clicks' component of the marker.\n",
"A callback may have as many inputs and outputs as needed, the linked function will be called when any one of the inputs is updated.\n",
"\n",
"But two different callbacks can not have the same output, this is to prevent overlapping issues that could happen if the two callbacks are triggered at the same time.\n",
"\n",
"The function decorator may also have a third kind of argument : States. Just like inputs they are entry variables to the function, but updating them will not trigger the callback, their purpose is to give information on the state of the app.\n",
"Here we choose a color for the polygon with the selector, its values is a State, but the change only happens once the button is clicked because it is the input."
# Tetras-Lab for interactive geographical data visualisation
In this galery you will learn how to create dashboards using the open source data intelligence platform Tetras-Lab and easily visualize and share them as a web app.
## Set up
We will be using the python libraries Dash and Dash-Leaflet, which can be easily added to Tetras-Lab, to create the components to be displayed in our dashboard.
The following imports are gonna be required :
```Python
from dash import html
import dash_leaflet as dl
import dash_leaflet.express as dlx
from jupyter_dash import JupyterDash as Dash
from dash_extensions.javascript import arrow_function, assign
from dash_extensions.enrich import Output, DashProxy, Input, MultiplexerTransform, State
from dash.dependencies import Output, Input
from dash import dcc
import dash_bootstrap_components as dbc
import plotly.express as px
```
## Basic layout
The first part of a Dash application is the layout, first of all we have to initialize our app :
Then we can add the components we want to the app layout, each component works like a HTML element to which we can set a CSS style attribute to manage its size, color, font, etc...
Exemple for a dropdown selector, first we declare the component :
We will now use the Dash_Leaflet Library to display an interactive map, the component to use is ```dl.Map()``` , without adding anything else, the only thing that will be displayed is a grey square, we need to draw some map tiles. By adding ``` dl.TileLayer()``` as an argument, Dash Leaflet will add a basic map layer.
We will now use the Dash_Leaflet Library to display an interactive map, the component to use is ```dl.Map()``` , without adding anything else, the only thing that will be displayed is a grey square, we need to draw some map tiles. By adding ``` dl.TileLayer()``` as an argument, Dash Leaflet will add a default map layer based on OpenStreetMap.
A Dash callback is made of 2 parts : A function that will be called when a specified component is updated, and a function decorator which will define the inputs : the variables the app is gonna watch for updates, and the output : the component that's gonna be changed when the function is called.
This decorator means the app will be looking for any updates to the number of times the marker has been clicked, and that the result of the following function will be sent to the component with the 'result' id.
```Python
def print_click(n):
return str(n)
```
The print_click function will be called every time the app detects an update on the 'n_clicks' component of the marker.
A callback may have as many inputs and outputs as needed, the linked function will be called when any one of the inputs is updated.
But two different callbacks can not have the same output, this is to prevent overlapping issues that could happen if the two callbacks are triggered at the same time.
The function decorator may also have a third kind of argument : States. Just like inputs they are entry variables to the function, but updating them will not trigger the callback, their purpose is to give information on the state of the app.
Here we choose a color for the polygon with the selector, its values is a State, but the change only happens once the button is clicked because it is the input.
"Then we can add the components we want to the app layout, each component works like a HTML element to which we can set a CSS style attribute to manage its size, color, font, etc...\n",
"We will now use the Dash_Leaflet Library to display an interactive map, the component to use is ```dl.Map()``` , without adding anything else, the only thing that will be displayed is a grey square, we need to draw some map tiles. By adding ``` dl.TileLayer()``` as an argument, Dash Leaflet will add a basic map layer.\n",
"We will now use the Dash_Leaflet Library to display an interactive map, the component to use is ```dl.Map()``` , without adding anything else, the only thing that will be displayed is a grey square, we need to draw some map tiles. By adding ``` dl.TileLayer()``` as an argument, Dash Leaflet will add a default map layer based on OpenStreetMap.\n",
"Now that we have our map, let's see what we can do with it. \n",
"\n",
"The ```children``` attribute of the map component allows us to add different kinds of layers to the map.\n",
"\n",
"Markers : \n",
"The ```children``` attribute of the map component allows us to add different kinds of layers to the map such as markers, polygons, and many others.\n",
"\n",
"```Python\n",
"marker = dl.Marker(position = [46.5,2.25])\n",
"marker = dl.Marker(position = [46.5,2.25], id ='marker')\n",
"A Dash callback is made of 2 parts : A function that will be called when a specified component is updated, and a function decorator which will define the inputs : the variables the app is gonna watch for updates, and the output : the component that's gonna be changed when the function is called. \n",
"This decorator means the app will be looking for any updates to the number of times the marker has been clicked, and that the result of the following function will be sent to the component with the 'result' id.\n",
"\n",
"```Python\n",
"def print_click(n):\n",
" return str(n)\n",
"``` \n",
"\n",
"The print_click function will be called every time the app detects an update on the 'n_clicks' component of the marker.\n",
"A callback may have as many inputs and outputs as needed, the linked function will be called when any one of the inputs is updated.\n",
"\n",
"But two different callbacks can not have the same output, this is to prevent overlapping issues that could happen if the two callbacks are triggered at the same time.\n",
"\n",
"The function decorator may also have a third kind of argument : States. Just like inputs they are entry variables to the function, but updating them will not trigger the callback, their purpose is to give information on the state of the app.\n",
"Here we choose a color for the polygon with the selector, its values is a State, but the change only happens once the button is clicked because it is the input."
# Tetras-Lab for interactive geographical data visualisation
In this galery you will learn how to create dashboards using the open source data intelligence platform Tetras-Lab and easily visualize and share them as a web app.
## Set up
We will be using the python libraries Dash and Dash-Leaflet, which can be easily added to Tetras-Lab, to create the components to be displayed in our dashboard.
The following imports are gonna be required :
```Python
from dash import html
import dash_leaflet as dl
import dash_leaflet.express as dlx
from jupyter_dash import JupyterDash as Dash
from dash_extensions.javascript import arrow_function, assign
from dash_extensions.enrich import Output, DashProxy, Input, MultiplexerTransform, State
from dash.dependencies import Output, Input
from dash import dcc
import dash_bootstrap_components as dbc
import plotly.express as px
```
## Basic layout
The first part of a Dash application is the layout, first of all we have to initialize our app :
Then we can add the components we want to the app layout, each component works like a HTML element to which we can set a CSS style attribute to manage its size, color, font, etc...
Exemple for a dropdown selector, first we declare the component :
We will now use the Dash_Leaflet Library to display an interactive map, the component to use is ```dl.Map()``` , without adding anything else, the only thing that will be displayed is a grey square, we need to draw some map tiles. By adding ``` dl.TileLayer()``` as an argument, Dash Leaflet will add a basic map layer.
We will now use the Dash_Leaflet Library to display an interactive map, the component to use is ```dl.Map()``` , without adding anything else, the only thing that will be displayed is a grey square, we need to draw some map tiles. By adding ``` dl.TileLayer()``` as an argument, Dash Leaflet will add a default map layer based on OpenStreetMap.
A Dash callback is made of 2 parts : A function that will be called when a specified component is updated, and a function decorator which will define the inputs : the variables the app is gonna watch for updates, and the output : the component that's gonna be changed when the function is called.
This decorator means the app will be looking for any updates to the number of times the marker has been clicked, and that the result of the following function will be sent to the component with the 'result' id.
```Python
def print_click(n):
return str(n)
```
The print_click function will be called every time the app detects an update on the 'n_clicks' component of the marker.
A callback may have as many inputs and outputs as needed, the linked function will be called when any one of the inputs is updated.
But two different callbacks can not have the same output, this is to prevent overlapping issues that could happen if the two callbacks are triggered at the same time.
The function decorator may also have a third kind of argument : States. Just like inputs they are entry variables to the function, but updating them will not trigger the callback, their purpose is to give information on the state of the app.
Here we choose a color for the polygon with the selector, its values is a State, but the change only happens once the button is clicked because it is the input.