Plotly for Wagtail CMS
Project description
Wagtail Plotly
Provides tabular data input for interactive visualisations in Wagtail. Developers manage plot availablity and styling in code with an option to allow users to apply further styling via JSON via admin. It uses Plotly.py and so it should be possible to hoist any of Plotlys supported visualisations into Wagtail easily.
Installation
Install from PyPI:
pip install wagtail-plotly
Then add the following to your project's INSTALLED_APPS
.
'wagtail.contrib.table_block',
'wagtail_plotly',
'wagtail_json_widget',
Settings
WAGTAIL_PLOTLY_INCLUDE_PLOTLYJS
Default: 'https://cdn.plot.ly/plotly-1.58.4.min.js'
A url string providing the location of a Plotly JS libarary
DEFAULT_PLOTLY_JSON_DIRECTORY
Default: 'plotly'
The name of the app
directory in which to look for custom json plots. Wagtail Plotly will search all installed apps looking for a directory matching the DEFAULT_PLOTLY_JSON_DIRECTORY
value and will attempt to load any .json
files it contains. See Customising for more information.
Usage overview
There are several plot blocks that you can use out of the box:
Adding one of these blocks provides you with input fields to manage the content of your plot, primarily titles and data, and a layout/style option(s). There is one default option out-of-the-box and more can be added by developers via .json
files using Plotly's schema. See Customising
This app also provides versions of the above blocks that support case by case customisation via a json field in the CMS UI.
Example use
One way of using it is to create a StreamBlock
:
from wagtail import blocks
from wagtail_plotly.blocks import (
BarChartBlock,
ContourPlotBlock,
HeatmapPlotBlock,
LinePlotBlock,
PieChartBlock,
ScatterPlotBlock,
)
class MyStreamBlock(blocks.StreamBlock):
bar_chart = BarChartBlock()
contour_plot = ContourPlotBlock()
heatmap_plot = HeatmapPlotBlock()
line_plot = LinePlotBlock()
pie_chart = PieChartBlock()
scatter_plot = ScatterPlotBlock()
Add the StreamBlock
to a StreamField
on a Wagtail page:
from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.fields import StreamField
from wagtail.models import Page
from .blocks import MyStreamBlock
class MyPage(Page):
body = StreamField(MyStreamBlock(), null=True)
content_panels = Page.content_panels + [
StreamFieldPanel('body'),
]
Then in the page template:
{% load static wagtailcore_tags %}
{% include_block page.body %}
Customising
Configuring plotly
graphs can be complex because there are a lot of options available. plotly
provide Chart Studio from which graphs and layouts can be made and exported as JSON data.
Wagtail Plotly is designed to consume a subset of this data with minimal effort by developers:
Wagtail Plotly will look for directories named plotly
(by default) in each installed app and any .json
files therein are assumed to be configuration options that are presented to users as Graph layout
options. In this way developers can provide managed plot configurations to end-users that override the default settings.
For example: my_plot.json
might contain:
{
"layout": {
"xaxis": {
"gridcolor": "#dddddd",
"mirror": true
},
"yaxis": {
"gridcolor": "#dddddd",
"mirror": true
},
"autosize": true,
"colorway": [
"#4c78a8",
"#f58518",
"#e45756",
"#72b7b2",
"#54a24b",
"#eeca3b",
"#b279a2",
"#ff9da6",
"#9d755d",
"#bab0ac"
]
}
}
Customising StreamField Blocks
Plots in Wagtail Plotly are a set of Wagtail StreamField blocks that share a common base BasePlotBlock
. They can be used as is or extended to create custom plots or features of Plotly that aren't (yet) handled by default.
All of the blocks have a plot_data
field for entering plot data (based on wagtail.contrib.table_block
) and build_data
method for extracting data from the table ready for plotting.
Creating new plot blocks
New plot blocks can be created in the usual way: subclassing from eitherBasePlotBlock
or one of the above blocks.
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
File details
Details for the file wagtail_plotly-0.0.4.tar.gz
.
File metadata
- Download URL: wagtail_plotly-0.0.4.tar.gz
- Upload date:
- Size: 15.2 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.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be6b866941ca9024749243028231238de3e2a0dab5fc6fa825452b2c2adbefd2 |
|
MD5 | 365a8fc6e8c0f2658d27cc943e08675d |
|
BLAKE2b-256 | 26c871e8494de41239d2c8e4a73ee12b431278fd5fc95066b9072dbc88150f6d |
File details
Details for the file wagtail_plotly-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: wagtail_plotly-0.0.4-py3-none-any.whl
- Upload date:
- Size: 14.6 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.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc1676b75713f2879d0028f616e9231beef54ab69b7a00573b37b9af44faa03c |
|
MD5 | b01a2f477f15658ef1418c5cafeb7a21 |
|
BLAKE2b-256 | 18c40b035aa3a1fe6a92ed42144070fd7bfec6bf23ac4623217b9ade2a0f7d5f |