CleverMaps Marimo Widget - A widget for embedding CleverMaps visualizations in Marimo notebooks.
Project description
CleverMaps Jupyter Widget
A Jupyter widget for embedding and interacting with CleverMaps visualizations in Jupyter notebooks.
Installation
You can install the package using pip:
pip install clevermaps-jupyter-widget
Requirements
- Python >= 3.9
- Jupyter notebook or JupyterLab
- anywidget
Usage
Basic Usage
from cm_jupyter_widget.widget import CleverMapsWidget
# Create a widget with a view URL
widget = CleverMapsWidget(view_url="https://your-view-url")
# Display the widget
widget
Advanced Usage with Options
# Create a widget with custom options
widget = CleverMapsWidget(
view_url="https://your-view-url",
options='''{
"componentSettings": {
"infoBox": {
"defaultExpanded": false
},
"tools": {
"search": false
}
},
"theme": {
"colorPrimary": "#0055ff"
},
"interactivity": {
"afterClick": false
},
"fullScreenButton": {
"enabled": false
},
"studioLinkButton": {
"enabled": false
}
}'''
)
API Reference
Widget Properties
view_url(required): The URL of the CleverMaps view to displaybase_url(optional): The base URL for CleverMaps API (defaults to 'https://secure.clevermaps.io/')options(optional): A JSON string containing configuration options for the widgetadd_filter_callback(optional): A Python function that will be called when a filter is added. The function will be called without any arguments.
Methods
toggle_fit_all()
Fits all features in the current view.
add_filter(definition_id: str, values: Dict[str, Any], instance_id: str)
Adds a new filter to the view.
Parameters:
definition_id: The ID of the filter definitionvalues: Filter values (format depends on filter type)instance_id: The instance ID of the filter
Filter value formats:
- MultiSelect:
{"values": ["Male", 1, null]} - SingleSelect:
{"value": "selected_value"}or{"value": null} - Feature:
{"values": ["feature1", 1]}or{"values": null} - Histogram:
{"values": [1, 10], "nullFiltered": true}or{"values": [null, null]} - Date:
{"startDate": {"value": "2023-01-01"}, "endDate": {"value": "2023-12-31"}} - Indicator:
{"values": [min, max], "granularity": "year"}
set_filter(instance_id: str, value)
Sets the value of an existing filter.
Parameters:
instance_id: The instance ID of the filter to setvalue: The new filter value
remove_filter(instance_id: str)
Removes a filter from the view.
Parameters:
instance_id: The instance ID of the filter to remove
reset_filter(instance_id: str)
Resets a filter to its default state.
Parameters:
instance_id: The instance ID of the filter to reset
set_state(view_url: str)
Loads a new view URL.
Parameters:
view_url: The URL of the view to load
open_bookmark_modal()
Opens the bookmark modal dialog.
open_export_modal()
Opens the export modal dialog.
Examples
Using Filter Callbacks
def on_filter_added():
print("A filter was added")
# Handle the filter addition event
widget = CleverMapsWidget(view_url="your-view-url")
widget.add_filter_callback = on_filter_added
Check out the example notebook in the repository:
sdk-test.ipynb: Advanced usage and testing examples
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Karel Psota (karel.psota@clevermaps.io)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cm_jupyter_widget-0.3.1.tar.gz.
File metadata
- Download URL: cm_jupyter_widget-0.3.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf426ba92948ded3b109e10b6479edb5bd9b62041cbead50fa63ba4ee328432c
|
|
| MD5 |
4c632689af34bdafe6f38101a319bcba
|
|
| BLAKE2b-256 |
d4ed3e08304b79b08430fa4a82bc5846309cf51b4288e2c441d79a3edf54ed07
|
File details
Details for the file cm_jupyter_widget-0.3.1-py3-none-any.whl.
File metadata
- Download URL: cm_jupyter_widget-0.3.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71f9c43a6bea56ad4ea059cf195dd66dcf690a3bde0c56d601309fa600bfeca3
|
|
| MD5 |
df6ccc68a56f7d09567bb553d294a405
|
|
| BLAKE2b-256 |
b724f330a8112c9182fd98c14e08bdf4713f36882638fed6bbd7b704298ade25
|