Build custom Vega/Vega-Lite dashboards in Datasette.
Project description
datasette-vega-dashboards
Build custom Vega/Vega-Lite dashboards in Datasette, for presentation-ready plots and visualizations.
Installation
Install this plugin in the same environment as Datasette.
$ datasette install datasette-vega-dashboards
Tutorial
See the example fixture in example_fixture for a minimal example.
You can run the fixture via:
datasette -m metadata.json --template-dir templates/ sleep_log.db
and then open http://127.0.0.1:8001/sleep_log/read_sleep to see the dashboard.
In the minimal example, we create a canned query in metadata.json:
"read_sleep": {
"hide_sql": true,
"sql": "SELECT * FROM (SELECT * FROM sleep_log ORDER BY date DESC LIMIT 7) ORDER BY date",
"write": false
}
The template for this canned query is extended by editing the
templates/query-sleep_log-read_sleep.html file. You can use the
instructions provided in the Datasette custom template
documentation
to determine what the name of the file should be for other resources,
such as dashboards you want to display on a database or table.
Each graph should have a <script> tag wrapped in a <div> tag. The
<script> tag should contain the Vega/Vega-Lite specification, and
must have a type of either application/vnd.vegalite+json (for
Vega-Lite) or application/vnd.vega+json (for Vega). The <div> tag
will be used for rendering the actual graph, and should have whatever
CSS styling you want (such as setting the width or height).
<div style="width: 1000px">
<script type="application/vnd.vegalite+json">
/* insert vegalite spec here */
</script>
</div>
<div style="width: 1000px">
<script type="application/vnd.vega+json">
/* or, insert a vega spec here */
</script>
</div>
Note that the Vega-Lite spec need not contain a data field -- any data
field will be replaced by the plugin based on the data returned by the
canned query. For Vega specs, the data field will be prepended with a
new dataset with the name data.
Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd datasette-vega-dashboards
python3 -mvenv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest
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 datasette-vega-dashboards-1.2.tar.gz.
File metadata
- Download URL: datasette-vega-dashboards-1.2.tar.gz
- Upload date:
- Size: 284.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d420d3cffd1aa6d5889de0ba76e9994ed0ad11379b124c4bcd1550279ba916a
|
|
| MD5 |
c7ba6dea2dffdf9ff0d54a26a2d45009
|
|
| BLAKE2b-256 |
50a50c3aa80d3f8d8f185ab509bd3956f263729fa778c3f83e75861e05facae3
|
File details
Details for the file datasette_vega_dashboards-1.2-py3-none-any.whl.
File metadata
- Download URL: datasette_vega_dashboards-1.2-py3-none-any.whl
- Upload date:
- Size: 285.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6304483b3c196850e2c2b99134bb5b5c93d80943462cf69169a8ad85b7d5d248
|
|
| MD5 |
0ee75ed89a2303ae0a196dca1f0f758a
|
|
| BLAKE2b-256 |
c7ed53b21c54a82eabfe87ffa519fc8857d5fec96976af19a9b317f2f6a6658f
|