Skip to content

Commit ca21f68

Browse files
author
Mark Gibbs
committed
Added websocket bridge use as a template tag
1 parent 81cf917 commit ca21f68

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

demo/demo/templates/index.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<!DOCTYPE HTML>
22
<html>
3-
{%load staticfiles%}
43
{%load plotly_dash%}
54
<title>Simple stuff</title>
65
<body>
@@ -17,14 +16,5 @@
1716
{%plotly_app name="Ex2"%}
1817
</div>
1918
</body>
20-
<script src="{%static "channels/js/websocketbridge.js"%}"></script>
21-
<script>
22-
const wsb = new channels.WebSocketBridge();
23-
wsb.connect("/ws/channel");
24-
wsb.listen(function(action, stream) {
25-
console.log("WSB inbound");
26-
console.log(action);
27-
console.log(stream);
28-
});
29-
</script>
19+
{%plotly_message_pipe%}
3020
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{%load staticfiles%}
2+
<script src="{%static "channels/js/websocketbridge.js"%}"></script>
3+
<script>
4+
const wsb = new channels.WebSocketBridge();
5+
wsb.connect("{{url}}");
6+
wsb.listen(function(action, stream) {
7+
console.log("WSB inbound");
8+
console.log(action);
9+
console.log(stream);
10+
});
11+
</script>

django_plotly_dash/templatetags/plotly_dash.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ def plotly_app(context, name=None, slug=None, da=None, ratio=0.1, use_frameborde
3838

3939
return locals()
4040

41+
@register.inclusion_tag("django_plotly_dash/plotly_messaging.html", takes_context=True)
42+
def plotly_message_pipe(context, url=None):
43+
url = url and url or '/ws/channel'
44+
return locals()

0 commit comments

Comments
 (0)