Skip to content

Commit 88029ea

Browse files
author
Mark Gibbs
committed
First working demo example. Need to relocate demo template
1 parent 30c4aee commit 88029ea

File tree

14 files changed

+174
-2
lines changed

14 files changed

+174
-2
lines changed

demo/demo/plotly_apps.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import dash
2+
import dash_core_components as dcc
3+
import dash_html_components as html
4+
5+
from django_plotly_dash import DelayedDash
6+
7+
app = DelayedDash('SimpleExample')
8+
9+
app.layout = html.Div([
10+
dcc.RadioItems(
11+
id='dropdown-a',
12+
options=[{'label': i, 'value': i} for i in ['Canada', 'USA', 'Mexico']],
13+
value='Canada'
14+
),
15+
html.Div(id='output-a'),
16+
17+
dcc.RadioItems(
18+
id='dropdown-b',
19+
options=[{'label': i, 'value': i} for i in ['MTL', 'NYC', 'SF']],
20+
value='MTL'
21+
),
22+
html.Div(id='output-b')
23+
24+
])
25+
26+
@app.callback(
27+
dash.dependencies.Output('output-a', 'children'),
28+
[dash.dependencies.Input('dropdown-a', 'value')])
29+
def callback_a(dropdown_value):
30+
return 'You\'ve selected "{}"'.format(dropdown_value)
31+
32+
33+
@app.callback(
34+
dash.dependencies.Output('output-b', 'children'),
35+
[dash.dependencies.Input('dropdown-a', 'value'),
36+
dash.dependencies.Input('dropdown-b', 'value')])
37+
def callback_b(dropdown_value,other_dd):
38+
return 'You\'ve selected "{}"'.format(dropdown_value)
39+
40+
a2 = DelayedDash("Ex2")
41+
a2.layout = html.Div([
42+
dcc.RadioItems(id="dropdown-one",options=[{'label':i,'value':j} for i,j in [
43+
("BEER","Beer"),("WIne","wine"),]
44+
],value="Beer"),
45+
html.Div(id="output-one")
46+
])
47+
48+
@a2.callback(
49+
dash.dependencies.Output('output-one','children'),
50+
[dash.dependencies.Input('dropdown-one','value')]
51+
)
52+
def callback_c(*args,**kwargs):
53+
return "Args are %s and kwargs are %s" %("".join(*args),str(kwargs))
54+

demo/demo/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
'django.contrib.sessions',
3838
'django.contrib.messages',
3939
'django.contrib.staticfiles',
40+
41+
'django_plotly_dash',
4042
]
4143

4244
MIDDLEWARE = [

demo/demo/urls.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
1616
from django.contrib import admin
17-
from django.urls import path
17+
from django.urls import include, path
18+
19+
from django.views.generic import TemplateView
20+
21+
# Load demo plotly apps
22+
import demo.plotly_apps
1823

1924
urlpatterns = [
25+
path('', TemplateView.as_view(template_name='index.html')),
2026
path('admin/', admin.site.urls),
27+
path('django_plotly_dash/', include('django_plotly_dash.urls')),
2128
]

django_plotly_dash/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

django_plotly_dash/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class DjangoPlotlyDashConfig(AppConfig):
5+
name = 'django_plotly_dash'

django_plotly_dash/dash_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _RepDash(self):
3737

3838
def _form_repdash(self):
3939
rd = NotDash(name_root=self._uid,
40-
app_pathname="dexy:main")
40+
app_pathname="django_plotly_dash:main")
4141
rd.layout = self.layout
4242
for cb, func in self._callback_sets:
4343
rd.callback(**cb)(func)

django_plotly_dash/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
<iframe src="{{url}}"></iframe>
3+
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
{%load dexy%}
4+
<title>Simple stuff</title>
5+
<body>
6+
<div>
7+
Content here
8+
{%plotly_item "SimpleExample"%}
9+
</div>
10+
<div>
11+
Content here
12+
{%plotly_item "SimpleExample"%}
13+
</div>
14+
<div>
15+
Content here
16+
{%plotly_item "Ex2"%}
17+
</div>
18+
</body>
19+
</html>

django_plotly_dash/templatetags/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)