Skip to main content

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.

Some more examples

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.

Release files for wagtail-plotly 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-plotly 0.0.4
File Size Uploaded
wagtail_plotly-0.0.4.tar.gz 15.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-plotly 0.0.4
File Interpreter ABI Platform
wagtail_plotly-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 29.8 kB

Release files / wagtail_plotly-0.0.4.tar.gz

Download URL wagtail_plotly-0.0.4.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
be6b866941ca9024749243028231238de3e2a0dab5fc6fa825452b2c2adbefd2
BLAKE2b-256 checksum
How to use checksums
26c871e8494de41239d2c8e4a73ee12b431278fd5fc95066b9072dbc88150f6d
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / wagtail_plotly-0.0.4-py3-none-any.whl

Download URL wagtail_plotly-0.0.4-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc1676b75713f2879d0028f616e9231beef54ab69b7a00573b37b9af44faa03c
BLAKE2b-256 checksum
How to use checksums
18c40b035aa3a1fe6a92ed42144070fd7bfec6bf23ac4623217b9ade2a0f7d5f
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page