django-plotly-dash


Namedjango-plotly-dash JSON
Version 2.3.1 PyPI version JSON
download
home_pagehttps://github.com/GibbsConsulting/django-plotly-dash
SummaryDjango use of plotly dash apps through template tags
upload_time2024-03-29 18:39:01
maintainerNone
docs_urlNone
authorMark Gibbs
requires_python>=3.8
licenseMIT
keywords django plotly plotly-dash dash dashboard
VCS
bugtrack_url
requirements dash plotly dpd-components dash-bootstrap-components channels Django Flask Werkzeug
Travis-CI
coveralls test coverage No coveralls.
            # django-plotly-dash

[![PyPI version](https://badge.fury.io/py/django-plotly-dash.svg)](https://badge.fury.io/py/django-plotly-dash)
[![Downloads](https://img.shields.io/pypi/dw/django-plotly-dash.svg)](https://img.shields.io/pypi/dw/django-plotly-dash.svg)
![Develop Branch Build Status](https://travis-ci.org/GibbsConsulting/django-plotly-dash.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/GibbsConsulting/django-plotly-dash/badge.svg?branch=master)](https://coveralls.io/github/GibbsConsulting/django-plotly-dash?branch=master)
[![Documentation Status](https://readthedocs.org/projects/django-plotly-dash/badge/?version=latest)](https://django-plotly-dash.readthedocs.io/en/latest/?badge=latest)

Expose [plotly dash](https://plot.ly/products/dash/) apps as [Django](https://www.djangoproject.com/) tags. Multiple Dash apps can
then be embedded into a single web page, persist and share internal state, and also have access to the
current user and session variables.

See the source for this project here:
<https://github.com/GibbsConsulting/django-plotly-dash>

This README file provides a short guide to installing and using the package, and also
outlines how to run the demonstration application.

More detailed information
can be found in the online documentation at
<https://readthedocs.org/projects/django-plotly-dash>

An online version of the demo can be found at <https://djangoplotlydash.com>


## Installation

First, install the package. This will also install plotly and some dash packages if they are not already present.

    pip install django_plotly_dash

Then, add `django_plotly_dash` to `INSTALLED_APPS` in your Django `settings.py` file

    INSTALLED_APPS = [
        ...
        'django_plotly_dash.apps.DjangoPlotlyDashConfig',
        ...
        ]

The application's routes need to be registered within the routing structure by an appropriate ``include`` statement in
a ``urls.py`` file. Note: `django_plotly_dash` is not a name of your application, it is referring to the inner namespace of this library. Please do not skip this step:

    urlpatterns = [
        ...
        path('django_plotly_dash/', include('django_plotly_dash.urls')),
    ]

The name within the URL is not important and can be changed.

For the final installation step, a migration is needed to update the
database:

    ./manage.py migrate

The use of frames within
HTML documents has to be enabled by adding to the ``settings.py`` file:

    X_FRAME_OPTIONS = 'SAMEORIGIN'


Further configuration, including live updating to share application
state, is described in the [online documentation](https://django-plotly-dash.readthedocs.io/en/latest/).

## Demonstration

The source repository contains a demo application. To clone the repo and lauch the demo:

```bash
git clone https://github.com/GibbsConsulting/django-plotly-dash.git

cd django-plotly-dash

./make_env                # sets up a virtual environment for development
                          #   with direct use of the source code for the package

./prepare_redis           # downloads a redis docker container
                          #   and launches it with default settings
                          #   *THIS STEP IS OPTIONAL*

./prepare_demo            # prepares and launches the demo
                          #   using the Django debug server at http://localhost:8000
```

## Usage

To use existing dash applications, first register them using the `DjangoDash` class. This
replaces the `Dash` class of the `dash` package.

Taking a very simple example inspired by the excellent [getting started](https://dash.plot.ly/) documentation:

```python
import dash
from dash import dcc, html

from django_plotly_dash import DjangoDash

app = DjangoDash('SimpleExample')

app.layout = html.Div([
    dcc.RadioItems(
        id='dropdown-color',
        options=[{'label': c, 'value': c.lower()} for c in ['Red', 'Green', 'Blue']],
        value='red'
    ),
    html.Div(id='output-color'),
    dcc.RadioItems(
        id='dropdown-size',
        options=[{'label': i, 'value': j} for i, j in [('L','large'), ('M','medium'), ('S','small')]],
        value='medium'
    ),
    html.Div(id='output-size')

])

@app.callback(
    dash.dependencies.Output('output-color', 'children'),
    [dash.dependencies.Input('dropdown-color', 'value')])
def callback_color(dropdown_value):
    return "The selected color is %s." % dropdown_value

@app.callback(
    dash.dependencies.Output('output-size', 'children'),
    [dash.dependencies.Input('dropdown-color', 'value'),
     dash.dependencies.Input('dropdown-size', 'value')])
def callback_size(dropdown_color, dropdown_size):
    return "The chosen T-shirt is a %s %s one." %(dropdown_size,
                                                  dropdown_color)
```

Note that the `DjangoDash` constructor requires a name to be specified. This name is then used to identify the dash app in
templates:

```jinja2
{% load plotly_dash %}

{% plotly_app name="SimpleExample" %}
```

The registration code needs to be in a location
that will be imported into the Django process before any model or template tag attempts to use it. The example Django application
in the demo subdirectory achieves this through an import in the main `urls.py` file; any `views.py` would also be sufficient.

Whilst this example allows for the direct use of existing `Dash` applications, it does not provide for the sharing or updating of
internal state. The [online documentation](https://django-plotly-dash.readthedocs.io/en/latest/) provides details on using these
and other additional features.

## Development

The `make_env` script sets up the development environment, and pulls in the packages
specified in the `dev_requirements.txt` file. The `check_code` script invokes the test suite (using `pytest`) as well
as invoking `pylint` on both the package and the associated demo.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/GibbsConsulting/django-plotly-dash",
    "name": "django-plotly-dash",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "django plotly plotly-dash dash dashboard",
    "author": "Mark Gibbs",
    "author_email": "django_plotly_dash@gibbsconsulting.ca",
    "download_url": "https://files.pythonhosted.org/packages/e7/fe/db37995be507b42af73b6e4b76cc510747552c387236dd4046962925ab5b/django-plotly-dash-2.3.1.tar.gz",
    "platform": null,
    "description": "# django-plotly-dash\n\n[![PyPI version](https://badge.fury.io/py/django-plotly-dash.svg)](https://badge.fury.io/py/django-plotly-dash)\n[![Downloads](https://img.shields.io/pypi/dw/django-plotly-dash.svg)](https://img.shields.io/pypi/dw/django-plotly-dash.svg)\n![Develop Branch Build Status](https://travis-ci.org/GibbsConsulting/django-plotly-dash.svg?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/GibbsConsulting/django-plotly-dash/badge.svg?branch=master)](https://coveralls.io/github/GibbsConsulting/django-plotly-dash?branch=master)\n[![Documentation Status](https://readthedocs.org/projects/django-plotly-dash/badge/?version=latest)](https://django-plotly-dash.readthedocs.io/en/latest/?badge=latest)\n\nExpose [plotly dash](https://plot.ly/products/dash/) apps as [Django](https://www.djangoproject.com/) tags. Multiple Dash apps can\nthen be embedded into a single web page, persist and share internal state, and also have access to the\ncurrent user and session variables.\n\nSee the source for this project here:\n<https://github.com/GibbsConsulting/django-plotly-dash>\n\nThis README file provides a short guide to installing and using the package, and also\noutlines how to run the demonstration application.\n\nMore detailed information\ncan be found in the online documentation at\n<https://readthedocs.org/projects/django-plotly-dash>\n\nAn online version of the demo can be found at <https://djangoplotlydash.com>\n\n\n## Installation\n\nFirst, install the package. This will also install plotly and some dash packages if they are not already present.\n\n    pip install django_plotly_dash\n\nThen, add `django_plotly_dash` to `INSTALLED_APPS` in your Django `settings.py` file\n\n    INSTALLED_APPS = [\n        ...\n        'django_plotly_dash.apps.DjangoPlotlyDashConfig',\n        ...\n        ]\n\nThe application's routes need to be registered within the routing structure by an appropriate ``include`` statement in\na ``urls.py`` file. Note: `django_plotly_dash` is not a name of your application, it is referring to the inner namespace of this library. Please do not skip this step:\n\n    urlpatterns = [\n        ...\n        path('django_plotly_dash/', include('django_plotly_dash.urls')),\n    ]\n\nThe name within the URL is not important and can be changed.\n\nFor the final installation step, a migration is needed to update the\ndatabase:\n\n    ./manage.py migrate\n\nThe use of frames within\nHTML documents has to be enabled by adding to the ``settings.py`` file:\n\n    X_FRAME_OPTIONS = 'SAMEORIGIN'\n\n\nFurther configuration, including live updating to share application\nstate, is described in the [online documentation](https://django-plotly-dash.readthedocs.io/en/latest/).\n\n## Demonstration\n\nThe source repository contains a demo application. To clone the repo and lauch the demo:\n\n```bash\ngit clone https://github.com/GibbsConsulting/django-plotly-dash.git\n\ncd django-plotly-dash\n\n./make_env                # sets up a virtual environment for development\n                          #   with direct use of the source code for the package\n\n./prepare_redis           # downloads a redis docker container\n                          #   and launches it with default settings\n                          #   *THIS STEP IS OPTIONAL*\n\n./prepare_demo            # prepares and launches the demo\n                          #   using the Django debug server at http://localhost:8000\n```\n\n## Usage\n\nTo use existing dash applications, first register them using the `DjangoDash` class. This\nreplaces the `Dash` class of the `dash` package.\n\nTaking a very simple example inspired by the excellent [getting started](https://dash.plot.ly/) documentation:\n\n```python\nimport dash\nfrom dash import dcc, html\n\nfrom django_plotly_dash import DjangoDash\n\napp = DjangoDash('SimpleExample')\n\napp.layout = html.Div([\n    dcc.RadioItems(\n        id='dropdown-color',\n        options=[{'label': c, 'value': c.lower()} for c in ['Red', 'Green', 'Blue']],\n        value='red'\n    ),\n    html.Div(id='output-color'),\n    dcc.RadioItems(\n        id='dropdown-size',\n        options=[{'label': i, 'value': j} for i, j in [('L','large'), ('M','medium'), ('S','small')]],\n        value='medium'\n    ),\n    html.Div(id='output-size')\n\n])\n\n@app.callback(\n    dash.dependencies.Output('output-color', 'children'),\n    [dash.dependencies.Input('dropdown-color', 'value')])\ndef callback_color(dropdown_value):\n    return \"The selected color is %s.\" % dropdown_value\n\n@app.callback(\n    dash.dependencies.Output('output-size', 'children'),\n    [dash.dependencies.Input('dropdown-color', 'value'),\n     dash.dependencies.Input('dropdown-size', 'value')])\ndef callback_size(dropdown_color, dropdown_size):\n    return \"The chosen T-shirt is a %s %s one.\" %(dropdown_size,\n                                                  dropdown_color)\n```\n\nNote that the `DjangoDash` constructor requires a name to be specified. This name is then used to identify the dash app in\ntemplates:\n\n```jinja2\n{% load plotly_dash %}\n\n{% plotly_app name=\"SimpleExample\" %}\n```\n\nThe registration code needs to be in a location\nthat will be imported into the Django process before any model or template tag attempts to use it. The example Django application\nin the demo subdirectory achieves this through an import in the main `urls.py` file; any `views.py` would also be sufficient.\n\nWhilst this example allows for the direct use of existing `Dash` applications, it does not provide for the sharing or updating of\ninternal state. The [online documentation](https://django-plotly-dash.readthedocs.io/en/latest/) provides details on using these\nand other additional features.\n\n## Development\n\nThe `make_env` script sets up the development environment, and pulls in the packages\nspecified in the `dev_requirements.txt` file. The `check_code` script invokes the test suite (using `pytest`) as well\nas invoking `pylint` on both the package and the associated demo.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django use of plotly dash apps through template tags",
    "version": "2.3.1",
    "project_urls": {
        "Documentation": "http://django-plotly-dash.readthedocs.io/",
        "Homepage": "https://github.com/GibbsConsulting/django-plotly-dash",
        "Source": "https://github.com/GibbsConsulting/django-plotly-dash",
        "Tracker": "https://github.com/GibbsConsulting/django-plotly-dash/issues"
    },
    "split_keywords": [
        "django",
        "plotly",
        "plotly-dash",
        "dash",
        "dashboard"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "da588f0fcfc16928c468c43a5c9045516382de442960bf47b797c5e86d0f5cf5",
                "md5": "eee4e236a7e61ee5c4be039e4199dd3f",
                "sha256": "1a0da2a1547ab394076febc16802ddc9aa8f21fbfd2ba1b41a2093f5c4a31551"
            },
            "downloads": -1,
            "filename": "django_plotly_dash-2.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eee4e236a7e61ee5c4be039e4199dd3f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 55361,
            "upload_time": "2024-03-29T18:38:44",
            "upload_time_iso_8601": "2024-03-29T18:38:44.854680Z",
            "url": "https://files.pythonhosted.org/packages/da/58/8f0fcfc16928c468c43a5c9045516382de442960bf47b797c5e86d0f5cf5/django_plotly_dash-2.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e7fedb37995be507b42af73b6e4b76cc510747552c387236dd4046962925ab5b",
                "md5": "03ab1531090aeb589bdae95689b72bd3",
                "sha256": "715a827a5d02d1d6e646a9ea415bd27c3ba06c45f1c300f48f89c0a6301dc551"
            },
            "downloads": -1,
            "filename": "django-plotly-dash-2.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "03ab1531090aeb589bdae95689b72bd3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 40570,
            "upload_time": "2024-03-29T18:39:01",
            "upload_time_iso_8601": "2024-03-29T18:39:01.725291Z",
            "url": "https://files.pythonhosted.org/packages/e7/fe/db37995be507b42af73b6e4b76cc510747552c387236dd4046962925ab5b/django-plotly-dash-2.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-29 18:39:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "GibbsConsulting",
    "github_project": "django-plotly-dash",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "dash",
            "specs": [
                [
                    "<",
                    "2.10"
                ],
                [
                    ">=",
                    "2.0"
                ]
            ]
        },
        {
            "name": "plotly",
            "specs": []
        },
        {
            "name": "dpd-components",
            "specs": []
        },
        {
            "name": "dash-bootstrap-components",
            "specs": []
        },
        {
            "name": "channels",
            "specs": [
                [
                    ">=",
                    "4.0"
                ]
            ]
        },
        {
            "name": "Django",
            "specs": [
                [
                    ">=",
                    "4.0.0"
                ]
            ]
        },
        {
            "name": "Flask",
            "specs": [
                [
                    ">=",
                    "1.0.2"
                ]
            ]
        },
        {
            "name": "Werkzeug",
            "specs": []
        }
    ],
    "lcname": "django-plotly-dash"
}
        
Elapsed time: 0.21592s