Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ coverage.xml
*.log
local_settings.py
*/db.sqlite3
demo/static/*

# Flask stuff:
instance/
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ See the source for this project here:
This README file provides a short guide to installing and using the package, and also
outlines how to run the demonstration application.



More detailed information
can be found in the online documentation at
<https://readthedocs.org/projects/django-plotly-dash>
Expand Down Expand Up @@ -105,5 +103,5 @@ templates:

The registration code needs to be in a location
that will be imported into the Django process before any model or template tag attempts to use it. The example Django application
in the demo subdirectory achieves this through an import in the main urls.py file; any views.py would also be sufficient.
in the demo subdirectory achieves this through an import in the main `urls.py` file; any `views.py` would also be sufficient.

10 changes: 10 additions & 0 deletions demo/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,13 @@
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')

STATICFILES_DIRS = [
]

import dash_core_components as dcc
_rname = os.path.join(os.path.dirname(dcc.__file__),'..')
for dash_module_name in ['dash_core_components','dash_html_components','dash_renderer',]:
STATICFILES_DIRS.append( ("dash/%s"%dash_module_name, os.path.join(_rname,dash_module_name)) )

2 changes: 1 addition & 1 deletion django_plotly_dash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#

__version__ = "0.1.0"
__version__ = "0.2.0"

from .dash_wrapper import DjangoDash

42 changes: 28 additions & 14 deletions django_plotly_dash/dash_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,30 @@ def have_current_state_entry(self, wid, key):
'Do nothing impl - only matters if state present'
pass

def form_dash_instance(self, replacements=None, specific_identifier=None):
def get_base_pathname(self, specific_identifier):
if not specific_identifier:
app_pathname = "%s:app-%s"% (app_name, main_view_label)
ndid = self._uid
else:
app_pathname="%s:%s" % (app_name, main_view_label)
ndid = specific_identifier

try:
full_url = reverse(app_pathname,kwargs={'id':ndid})
except:
full_url = "/%s/" %ndid

return ndid, full_url

def form_dash_instance(self, replacements=None, specific_identifier=None):

rd = NotDash(name_root=self._uid,
app_pathname=app_pathname,
ndid, base_pathname = self.get_base_pathname(specific_identifier)

rd = NotDash(base_pathname=base_pathname,
expanded_callbacks = self._expanded_callbacks,
replacements = replacements,
specific_identifier = specific_identifier)
ndid = ndid)

rd.layout = self.layout

for cb, func in self._callback_sets:
Expand Down Expand Up @@ -126,22 +139,24 @@ def run(self,*args,**kwargs):
pass

class NotDash(Dash):
def __init__(self, name_root, app_pathname=None, replacements = None, specific_identifier=None, expanded_callbacks=False, **kwargs):
def __init__(self, base_pathname=None, replacements = None, ndid=None, expanded_callbacks=False, **kwargs):

if specific_identifier is not None:
self._uid = specific_identifier
else:
self._uid = name_root
self._uid = ndid

self._flask_app = Flask(self._uid)
self._notflask = NotFlask()
self._base_pathname = reverse(app_pathname,kwargs={'id':self._uid})
self._base_pathname = base_pathname

kwargs['url_base_pathname'] = self._base_pathname
kwargs['server'] = self._notflask

super(NotDash, self).__init__(**kwargs)

self.css.config.serve_locally = True
#self.css.config.serve_locally = False

self.scripts.config.serve_locally = self.css.config.serve_locally

self._adjust_id = False
self._dash_dispatch = not expanded_callbacks
if replacements:
Expand All @@ -158,17 +173,16 @@ def use_dash_layout(self):

def augment_initial_layout(self, base_response):
if self.use_dash_layout() and False:
return HttpResponse(base_response.data,
content_type=base_response.mimetype)
return base_response.data, base_response.mimetype
# Adjust the base layout response
baseDataInBytes = base_response.data
baseData = json.loads(baseDataInBytes.decode('utf-8'))
# Walk tree. If at any point we have an element whose id matches, then replace any named values at this level
reworked_data = self.walk_tree_and_replace(baseData)
response_data = json.dumps(reworked_data,
cls=PlotlyJSONEncoder)
return HttpResponse(response_data,
content_type=base_response.mimetype)

return response_data, base_response.mimetype

def walk_tree_and_extract(self, data, target):
if isinstance(data, dict):
Expand Down
4 changes: 3 additions & 1 deletion django_plotly_dash/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import path
from django.views.decorators.csrf import csrf_exempt

from .views import routes, layout, dependencies, update, main_view
from .views import routes, layout, dependencies, update, main_view, component_suites

from .app_name import app_name, main_view_label

Expand All @@ -11,11 +11,13 @@
path('instance/<slug:id>_dash-dependencies', dependencies, name="dependencies"),
path('instance/<slug:id>_dash-update-component', csrf_exempt(update), name="update-component"),
path('instance/<slug:id>', main_view, name=main_view_label),
path('instance/<slug:id>_dash-component-suites/<slug:component>/<resource>', component_suites, name='component-suites'),

path('app/<slug:id>_dash-routes', routes, {'stateless':True}, name="app-routes"),
path('app/<slug:id>_dash-layout', layout, {'stateless':True}, name="app-layout"),
path('app/<slug:id>_dash-dependencies', dependencies, {'stateless':True}, name="app-dependencies"),
path('app/<slug:id>_dash-update-component', csrf_exempt(update), {'stateless':True}, name="app-update-component"),
path('app/<slug:id>', main_view, {'stateless':True}, name='app-%s'%main_view_label),
path('app/<slug:id>_dash-component-suites/<slug:component>/<resource>', component_suites, {'stateless':True}, name='app-component-suites'),
]

15 changes: 13 additions & 2 deletions django_plotly_dash/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.http import HttpResponse, HttpResponseRedirect

import json

Expand All @@ -22,7 +22,9 @@ def layout(request, id, stateless=False, **kwargs):

mFunc = app.locate_endpoint_function('dash-layout')
resp = mFunc()
return app.augment_initial_layout(resp)
response_data, mimetype = app.augment_initial_layout(resp)
return HttpResponse(response_data,
content_type=mimetype)

def update(request, id, stateless=False, **kwargs):
da, app = DashApp.locate_item(id, stateless)
Expand Down Expand Up @@ -59,3 +61,12 @@ def main_view(request, id, stateless=False, **kwargs):
resp = mFunc()
return HttpResponse(resp)

def component_suites(request, resource=None, component=None, **kwargs):

eBig = request.GET.urlencode()
if len(eBig) > 0:
redone_url = "/static/dash/%s/%s?%s" %(component, resource, eBig)
else:
redone_url = "/static/dash/%s/%s" %(component, resource)

return HttpResponseRedirect(redirect_to=redone_url)
6 changes: 0 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,3 @@ Contents
models_and_state


Indices and tables
------------------

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
1 change: 1 addition & 0 deletions prepare_demo
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ source env/bin/activate
cd demo
./manage.py migrate
./manage.py shell < configdb.py # Add a superuser if needed
./manage.py collectstatic -i "*.py" -i "*.pyc" --noinput --link
./manage.py runserver