Skip to content

Commit 865396c

Browse files
delsimGibbsConsulting
authored andcommitted
Add an example using dash-bootstrap-components (#98)
* v0.9.5 packages for future reference * Outline of application using dash-bootstrap-components * Extended urls to cover components in path name * Added use of existing bootstrap links
1 parent 3593bf4 commit 865396c

File tree

9 files changed

+113
-25
lines changed

9 files changed

+113
-25
lines changed

demo/demo/bootstrap_app.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'''
2+
Dash bootstrap component demo app
3+
4+
Copyright (c) 2018 Gibbs Consulting and others - see CONTRIBUTIONS.md
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
'''
24+
25+
import dash
26+
import dash_bootstrap_components as dbc
27+
import dash_html_components as html
28+
29+
from django_plotly_dash import DjangoDash
30+
31+
dd = DjangoDash("BootstrapApplication",
32+
add_bootstrap_links=True)
33+
34+
dd.layout = html.Div(
35+
[
36+
dbc.Alert("This is an alert", color="primary"),
37+
dbc.Alert("Danger", color="danger"),
38+
]
39+
)
40+

demo/demo/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
'dash_html_components',
188188
'dash_renderer',
189189
'dpd_components',
190+
'dash_bootstrap_components',
190191
]:
191192

192193
module = importlib.import_module(dash_module_name)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{%extends "base.html"%}
2+
{%load plotly_dash%}
3+
4+
{%block title%}Demo Seven - Dash Bootstrap Components{%endblock%}
5+
6+
{%block content%}
7+
<h1>Dash Bootstrap Components</h1>
8+
<p>
9+
This example demonstrates the use of the dash-bootstrap-components package.
10+
</p>
11+
<div class="card bg-light border-dark">
12+
<div class="card-body">
13+
<p><span>{</span>% load plotly_dash %}</p>
14+
<p>&lt;div class="<span>{</span>% plotly_class name="BootstrapApplication"%}">
15+
<p class="ml-3"><span>{</span>% plotly_app name="BootstrapApplication" %}</p>
16+
<p>&lt;\div>
17+
</div>
18+
</div>
19+
<p></p>
20+
<div class="card border-dark">
21+
<div class="card-body">
22+
<div class="{%plotly_class name="BootstrapApplication"%}">
23+
{%plotly_app name="BootstrapApplication"%}
24+
</div>
25+
</div>
26+
</div>
27+
{%endblock%}

demo/demo/templates/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ <h1>Demonstration Application</h1>
1313
<li><a class="btn btn-primary btnspace" href="{%url "demo-four"%}">Demo Four</a> - live updating of apps by pushing from the Django server</li>
1414
<li><a class="btn btn-primary btnspace" href="{%url "demo-five"%}">Demo Five</a> - injection of a Dash application without embedding in an html iframe</li>
1515
<li><a class="btn btn-primary btnspace" href="{%url "demo-six"%}">Demo Six</a> - simple html injection example</li>
16+
<li><a class="btn btn-primary btnspace" href="{%url "demo-seven"%}">Demo Seven</a> - dash-bootstrap-components example</li>
1617
</ul>
1718
{%endblock%}

demo/demo/urls.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
from django.conf.urls.static import static
2727

2828
# Load demo plotly apps - this triggers their registration
29-
import demo.plotly_apps # pylint: disable=unused-import
30-
import demo.dash_apps # pylint: disable=unused-import
29+
import demo.plotly_apps # pylint: disable=unused-import
30+
import demo.dash_apps # pylint: disable=unused-import
31+
import demo.bootstrap_app # pylint: disable=unused-import
3132

3233
from django_plotly_dash.views import add_to_session
3334

@@ -41,6 +42,7 @@
4142
url('^demo-four$', TemplateView.as_view(template_name='demo_four.html'), name="demo-four"),
4243
url('^demo-five$', TemplateView.as_view(template_name='demo_five.html'), name="demo-five"),
4344
url('^demo-six', dash_example_1_view, name="demo-six"),
45+
url('^demo-seven', TemplateView.as_view(template_name='demo_seven.html'), name="demo-seven"),
4446
url('^admin/', admin.site.urls),
4547
url('^django_plotly_dash/', include('django_plotly_dash.urls')),
4648

django_plotly_dash/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from django.urls import path
2828
from django.views.decorators.csrf import csrf_exempt
2929

30-
from .views import routes, layout, dependencies, update, main_view, component_suites
30+
from .views import routes, layout, dependencies, update, main_view, component_suites, component_component_suites
3131

3232
from .app_name import app_name, main_view_label
3333

@@ -47,6 +47,7 @@
4747
('_dash-update-component', csrf_exempt(update), 'update-component', '', ),
4848
('', main_view, main_view_label, '', ),
4949
('_dash-component-suites', component_suites, 'component-suites', '/<slug:component>/<resource>', ),
50+
('_dash-component-suites', component_component_suites, 'component-component-suites', '/<slug:component>/_components/<resource>', ),
5051
]:
5152

5253
route_name = '%s%s%s' % (name_prefix, name, name_suffix)

django_plotly_dash/views.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,21 @@ def main_view(request, ident, stateless=False, cache_id=None, **kwargs):
100100
resp = view_func()
101101
return HttpResponse(resp)
102102

103-
def component_suites(request, resource=None, component=None, **kwargs):
103+
def component_component_suites(request, resource=None, component=None, **kwargs):
104+
return component_suites(request,
105+
resource=resource,
106+
component=component,
107+
extra_element="_components/",
108+
**kwargs)
109+
110+
def component_suites(request, resource=None, component=None, extra_element="", **kwargs):
104111
'Return part of a client-side component, served locally for some reason'
105112

106113
get_params = request.GET.urlencode()
107114
if get_params:
108-
redone_url = "/static/dash/%s/%s?%s" %(component, resource, get_params)
115+
redone_url = "/static/dash/%s/%s%s?%s" %(component, extra_element, resource, get_params)
109116
else:
110-
redone_url = "/static/dash/%s/%s" %(component, resource)
117+
redone_url = "/static/dash/%s/%s%s" %(component, extra_element, resource)
111118

112119
return HttpResponseRedirect(redirect_to=redone_url)
113120

frozen_dev.txt

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,35 @@ astroid==2.0.4
66
async-timeout==2.0.1
77
atomicwrites==1.2.1
88
attrs==18.2.0
9-
autobahn==18.8.2
9+
autobahn==18.9.2
1010
Automat==0.7.0
1111
Babel==2.6.0
12+
bleach==3.0.2
1213
certifi==2018.8.24
14+
cffi==1.11.5
1315
channels==2.1.3
1416
channels-redis==2.3.0
1517
chardet==3.0.4
16-
click==6.7
18+
Click==7.0
19+
cmarkgfm==0.4.2
1720
constantly==15.1.0
1821
coverage==4.5.1
1922
daphne==2.2.2
20-
dash==0.28.5
21-
dash-core-components==0.28.1
22-
dash-html-components==0.11.0
23-
dash-renderer==0.13.2
23+
dash==0.28.2
24+
dash-core-components==0.33.0
25+
dash-html-components==0.13.2
26+
dash-renderer==0.14.3
2427
decorator==4.3.0
25-
Django==2.1.1
28+
Django==2.1.2
2629
django-bootstrap4==0.0.7
27-
-e git+https://github.com/delsim/django-plotly-dash.git@1a6a184eac871a0a675fa971fe4c10c3dac195d8#egg=django_plotly_dash
30+
-e git+https://github.com/delsim/django-plotly-dash.git@affccd8b280b2fdbc7f7e2d975b9cf4c7ace5f06#egg=django_plotly_dash
2831
django-redis==4.9.0
2932
docopt==0.6.2
3033
docutils==0.14
3134
dpd-components==0.1.0
3235
Flask==1.0.2
3336
Flask-Compress==1.4.0
37+
future==0.16.0
3438
grip==4.5.2
3539
hiredis==0.2.0
3640
hyperlink==18.0.0
@@ -45,34 +49,36 @@ jsonschema==2.6.0
4549
jupyter-core==4.4.0
4650
lazy-object-proxy==1.3.1
4751
livereload==2.5.2
48-
Markdown==2.6.11
52+
Markdown==3.0.1
4953
MarkupSafe==1.0
5054
mccabe==0.6.1
5155
more-itertools==4.3.0
5256
msgpack==0.5.6
5357
nbformat==4.4.0
54-
numpy==1.15.1
58+
numpy==1.15.2
5559
packaging==18.0
5660
pandas==0.23.4
5761
path-and-address==2.0.1
5862
pathlib2==2.3.2
5963
pathtools==0.1.2
6064
pkg-resources==0.0.0
6165
pkginfo==1.4.2
62-
plotly==3.1.1
66+
plotly==3.3.0
6367
pluggy==0.7.1
6468
port-for==0.3.1
65-
py==1.6.0
69+
py==1.7.0
70+
pycparser==2.19
6671
Pygments==2.2.0
6772
PyHamcrest==1.9.0
6873
pylint==2.1.1
69-
pyparsing==2.3.0
70-
pytest==3.7.4
71-
pytest-cov==2.5.1
72-
pytest-django==3.4.2
74+
pyparsing==2.2.2
75+
pytest==3.8.2
76+
pytest-cov==2.6.0
77+
pytest-django==3.4.3
7378
python-dateutil==2.7.3
7479
pytz==2018.5
7580
PyYAML==3.13
81+
readme-renderer==22.0
7682
redis==2.10.6
7783
requests==2.19.1
7884
requests-toolbelt==0.8.0
@@ -83,15 +89,16 @@ Sphinx==1.8.1
8389
sphinx-autobuild==0.7.1
8490
sphinx-rtd-theme==0.4.2
8591
sphinxcontrib-websupport==1.1.0
86-
tornado==5.1
87-
tqdm==4.25.0
92+
tornado==5.1.1
93+
tqdm==4.26.0
8894
traitlets==4.3.2
89-
twine==1.11.0
95+
twine==1.12.1
9096
Twisted==18.7.0
9197
txaio==18.8.1
9298
typed-ast==1.1.0
9399
urllib3==1.23
94100
watchdog==0.9.0
101+
webencodings==0.5.1
95102
Werkzeug==0.14.1
96103
wrapt==1.10.11
97104
zope.interface==4.5.0

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ dash-renderer
55
plotly
66
dpd-components
77

8+
dash-bootstrap-components
9+
810
Django>=2
911
Flask>=1.0.2

0 commit comments

Comments
 (0)