Skip to content

Commit 1595c15

Browse files
author
Mark Gibbs
committed
Async django interaction with Pipe component
1 parent c006deb commit 1595c15

File tree

8 files changed

+58
-5
lines changed

8 files changed

+58
-5
lines changed

demo/demo/consumers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
import json
44

55
class MessageConsumer(WebsocketConsumer):
6+
67
def connect(self):
78
self.accept()
9+
810
def disconnect(self, close_code):
911
pass
12+
13+
def send_to_widgets(self, channel_name, label, value):
14+
self.send(json.dumps({'channel_name':channel_name,
15+
'label':label,
16+
'value':value}))
1017
def receive(self, text_data):
1118
print("Got incoming")
1219
message = json.loads(text_data)
1320
print(text_data)
1421
self.send(json.dumps({'message':"Thanks for [%s]"%text_data}))
1522
self.send(json.dumps({'original_message':message}))
23+
24+
# TODO if type is connection_triplet then store and/or update the info
25+
# TODO else do something appropriate with the message
26+
27+
channel_name = message.get('channel_name',"UNNAMED_CHANNEL")
28+
uid = message.get('uid',"0000-0000")
29+
label = message.get('label','DEFAULT$LABEL')
30+
31+
self.send_to_widgets(channel_name=channel_name,
32+
label=label,
33+
value=uid)

demo/demo/plotly_apps.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import dash_core_components as dcc
33
import dash_html_components as html
44

5+
import dpd_components as dpd
6+
57
from django_plotly_dash import DjangoDash
68

79
app = DjangoDash('SimpleExample')
@@ -52,3 +54,26 @@ def callback_c(*args,**kwargs):
5254
da = kwargs['dash_app']
5355
return "Args are [%s] and kwargs are %s" %(",".join(args),str(kwargs))
5456

57+
a3 = DjangoDash("Connected")
58+
59+
a3.layout = html.Div([
60+
dpd.Pipe(id="dynamic",
61+
value="Dynamo 123",
62+
label="rotational energy",
63+
channel_name="test_widget_channel",
64+
uid="need_to_generate_this"),
65+
dpd.DPDirectComponent(id="direct"),
66+
dcc.RadioItems(id="dropdown-one",options=[{'label':i,'value':j} for i,j in [
67+
("O2","Oxygen"),("N2","Nitrogen"),("CO2","Carbon Dioxide")]
68+
],value="Oxygen"),
69+
html.Div(id="output-three")
70+
])
71+
72+
@a3.expanded_callback(
73+
dash.dependencies.Output('output-three','children'),
74+
[dash.dependencies.Input('dynamic','value'),
75+
dash.dependencies.Input('dynamic','label'),
76+
])
77+
def callback_a3(*args, **kwargs):
78+
da = kwargs['dash_app']
79+
return "Args are [%s] and kwargs are %s" %(",".join(args),str(kwargs))

demo/demo/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@
130130

131131
import dash_core_components as dcc
132132
_rname = os.path.join(os.path.dirname(dcc.__file__),'..')
133-
for dash_module_name in ['dash_core_components','dash_html_components','dash_renderer',]:
133+
for dash_module_name in ['dash_core_components',
134+
'dash_html_components',
135+
'dash_renderer',]:
134136
STATICFILES_DIRS.append( ("dash/%s"%dash_module_name, os.path.join(_rname,dash_module_name)) )
135137

138+
# Fudge to work with channels in debug mode
139+
STATICFILES_DIRS.append(("dash/dpd_components","/home/mark/local/dpd-components/lib"))

demo/demo/templates/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
Content here
1616
{%plotly_app name="Ex2"%}
1717
</div>
18+
<div>
19+
Content here
20+
{%plotly_app name="Connected"%}
21+
</div>
1822
</body>
1923
{%plotly_message_pipe%}
2024
</html>

dev_requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ nbformat==4.4.0
3939
packaging==17.1
4040
path-and-address==2.0.1
4141
pathtools==0.1.2
42-
pkg-resources==0.0.0
4342
pkginfo==1.4.2
4443
plotly==2.5.1
4544
port-for==0.3.1

django_plotly_dash/dash_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __init__(self, base_pathname=None, replacements = None, ndid=None, expanded_
155155
super(WrappedDash, self).__init__(**kwargs)
156156

157157
self.css.config.serve_locally = True
158-
self.css.config.serve_locally = False
158+
#self.css.config.serve_locally = False
159159

160160
self.scripts.config.serve_locally = self.css.config.serve_locally
161161

django_plotly_dash/templates/django_plotly_dash/plotly_messaging.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
console.log(stream);
2323
};
2424
dpd_wsb.add_callback(lcb);
25-
dpd_wsb.add_callback(lcb);
25+
if( window.dpd_wsb_pre ) {
26+
for(var i in window.dpd_wsb_pre.callbacks ) dpd_wsb.add_callback(window.dpd_wsb_pre.callbacks[i]);
27+
for(var j in window.dpd_wsb_pre.sender_targets ) window.dpd_wsb_pre.sender_targets[i].add_sender(dpd_wsb);
28+
}
2629
}
2730
</script>

make_env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
virtualenv -p python3 env
3+
virtualenv -p python3.6 env
44
source env/bin/activate
55
pip install -r requirements.txt
66
pip install -r dev_requirements.txt

0 commit comments

Comments
 (0)