Skip to content

Commit

Permalink
Dash 22 upgrade (#25)
Browse files Browse the repository at this point in the history
* Add dummy register_blueprint function

* Minor tweaks
  • Loading branch information
delsim authored and GibbsConsulting committed Jul 29, 2018
1 parent 9ba89e9 commit 27a5907
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
41 changes: 21 additions & 20 deletions demo/demo/plotly_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import uuid
import random

import pandas as pd

from datetime import datetime

import pandas as pd

from django.core.cache import cache

import dash
Expand All @@ -22,6 +22,8 @@
from django_plotly_dash import DjangoDash
from django_plotly_dash.consumers import send_to_pipe_channel

#pylint: disable=too-many-arguments, unused-argument, unused-variable

app = DjangoDash('SimpleExample')

app.layout = html.Div([
Expand Down Expand Up @@ -146,12 +148,12 @@ def callback_liveIn_button_press(red_clicks, blue_clicks, green_clicks,
timestamp = gc_timestamp
change_col = "green"

value={'red_clicks':red_clicks,
'blue_clicks':blue_clicks,
'green_clicks':green_clicks,
'click_colour':change_col,
'click_timestamp':timestamp,
'user':str(kwargs.get('user', 'UNKNOWN'))}
value = {'red_clicks':red_clicks,
'blue_clicks':blue_clicks,
'green_clicks':green_clicks,
'click_colour':change_col,
'click_timestamp':timestamp,
'user':str(kwargs.get('user', 'UNKNOWN'))}

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

liveOut = DjangoDash("LiveOutput",
)#serve_locally=True)
)#serve_locally=True)

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

# extract incoming info from the message and update the internal state
user = named_count.get('user', None)
click_colour = named_count.get('click_colour',None)
click_timestamp = named_count.get('click_timestamp',0)
click_colour = named_count.get('click_colour', None)
click_timestamp = named_count.get('click_timestamp', 0)

if click_colour:
colour_set = state.get(click_colour,None)
colour_set = state.get(click_colour, None)

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

_, last_ts, prev = colour_set[-1]
if click_timestamp > last_ts:
colour_set.append((user, click_timestamp, prev * random.lognormvariate(0.0,0.1)),)
colour_set.append((user, click_timestamp, prev * random.lognormvariate(0.0, 0.1)),)
colour_set = colour_set[-100:]

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

traces = [ go.Scatter(y=df[colour],
x=df['index'],
name=colour,
line=dict(color=colors[colour]),
) for colour in colour_series.keys() ]
traces = [go.Scatter(y=df[colour],
x=df['index'],
name=colour,
line=dict(color=colors[colour]),
) for colour in colour_series]

return {'data':traces,
#'layout': go.Layout
}

}
2 changes: 2 additions & 0 deletions django_plotly_dash/dash_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def before_first_request(self, *args, **kwargs):
pass
def run(self, *args, **kwargs):
pass
def register_blueprint(*args, **kwargs):
pass

class WrappedDash(Dash):
'Wrapper around the Plotly Dash application instance'
Expand Down
6 changes: 4 additions & 2 deletions django_plotly_dash/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

def _get_settings():
try:
return settings.PLOTLY_DASH
the_settings = settings.PLOTLY_DASH
except AttributeError:
return {}
the_settings = None

return the_settings if the_settings else {}

def pipe_ws_endpoint_name():
'Return the endpoint for pipe websocket connections'
Expand Down

0 comments on commit 27a5907

Please sign in to comment.