Skip to content

Commit 27a5907

Browse files
delsimGibbsConsulting
authored andcommitted
Dash 22 upgrade (#25)
* Add dummy register_blueprint function * Minor tweaks
1 parent 9ba89e9 commit 27a5907

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

demo/demo/plotly_apps.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import uuid
66
import random
77

8-
import pandas as pd
9-
108
from datetime import datetime
119

10+
import pandas as pd
11+
1212
from django.core.cache import cache
1313

1414
import dash
@@ -22,6 +22,8 @@
2222
from django_plotly_dash import DjangoDash
2323
from django_plotly_dash.consumers import send_to_pipe_channel
2424

25+
#pylint: disable=too-many-arguments, unused-argument, unused-variable
26+
2527
app = DjangoDash('SimpleExample')
2628

2729
app.layout = html.Div([
@@ -146,12 +148,12 @@ def callback_liveIn_button_press(red_clicks, blue_clicks, green_clicks,
146148
timestamp = gc_timestamp
147149
change_col = "green"
148150

149-
value={'red_clicks':red_clicks,
150-
'blue_clicks':blue_clicks,
151-
'green_clicks':green_clicks,
152-
'click_colour':change_col,
153-
'click_timestamp':timestamp,
154-
'user':str(kwargs.get('user', 'UNKNOWN'))}
151+
value = {'red_clicks':red_clicks,
152+
'blue_clicks':blue_clicks,
153+
'green_clicks':green_clicks,
154+
'click_colour':change_col,
155+
'click_timestamp':timestamp,
156+
'user':str(kwargs.get('user', 'UNKNOWN'))}
155157

156158
send_to_pipe_channel(channel_name="live_button_counter",
157159
label="named_counts",
@@ -162,7 +164,7 @@ def callback_liveIn_button_press(red_clicks, blue_clicks, green_clicks,
162164
datetime.fromtimestamp(0.001*timestamp))
163165

164166
liveOut = DjangoDash("LiveOutput",
165-
)#serve_locally=True)
167+
)#serve_locally=True)
166168

167169
def _get_cache_key(state_uid):
168170
return "demo-liveout-s4-%s" % state_uid
@@ -208,18 +210,18 @@ def callback_liveOut_pipe_in(named_count, state_uid, **kwargs):
208210

209211
# extract incoming info from the message and update the internal state
210212
user = named_count.get('user', None)
211-
click_colour = named_count.get('click_colour',None)
212-
click_timestamp = named_count.get('click_timestamp',0)
213+
click_colour = named_count.get('click_colour', None)
214+
click_timestamp = named_count.get('click_timestamp', 0)
213215

214216
if click_colour:
215-
colour_set = state.get(click_colour,None)
217+
colour_set = state.get(click_colour, None)
216218

217219
if not colour_set:
218220
colour_set = [(None, 0, 100) for i in range(5)]
219221

220222
_, last_ts, prev = colour_set[-1]
221223
if click_timestamp > last_ts:
222-
colour_set.append((user, click_timestamp, prev * random.lognormvariate(0.0,0.1)),)
224+
colour_set.append((user, click_timestamp, prev * random.lognormvariate(0.0, 0.1)),)
223225
colour_set = colour_set[-100:]
224226

225227
state[click_colour] = colour_set
@@ -257,13 +259,12 @@ def callback_show_timeseries(internal_state_string, state_uid, **kwargs):
257259
'green':'#00FF00',
258260
}
259261

260-
traces = [ go.Scatter(y=df[colour],
261-
x=df['index'],
262-
name=colour,
263-
line=dict(color=colors[colour]),
264-
) for colour in colour_series.keys() ]
262+
traces = [go.Scatter(y=df[colour],
263+
x=df['index'],
264+
name=colour,
265+
line=dict(color=colors[colour]),
266+
) for colour in colour_series]
265267

266268
return {'data':traces,
267269
#'layout': go.Layout
268-
}
269-
270+
}

django_plotly_dash/dash_wrapper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ def before_first_request(self, *args, **kwargs):
176176
pass
177177
def run(self, *args, **kwargs):
178178
pass
179+
def register_blueprint(*args, **kwargs):
180+
pass
179181

180182
class WrappedDash(Dash):
181183
'Wrapper around the Plotly Dash application instance'

django_plotly_dash/util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
def _get_settings():
88
try:
9-
return settings.PLOTLY_DASH
9+
the_settings = settings.PLOTLY_DASH
1010
except AttributeError:
11-
return {}
11+
the_settings = None
12+
13+
return the_settings if the_settings else {}
1214

1315
def pipe_ws_endpoint_name():
1416
'Return the endpoint for pipe websocket connections'

0 commit comments

Comments
 (0)