Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with requirejs and templates #1472

Merged
merged 7 commits into from
Jul 9, 2020
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
7 changes: 5 additions & 2 deletions panel/command/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import ast
import base64
import os

from bokeh.command.subcommands.serve import Serve as _BkServe

Expand Down Expand Up @@ -95,10 +96,12 @@ def customize_kwargs(self, args, server_kwargs):
kwargs['index'] = INDEX_HTML

# Handle tranquilized functions in the supplied functions
kwargs['extra_patterns'] = patterns = []
kwargs['extra_patterns'] = patterns = kwargs.get('extra_patterns', [])

if args.static_dirs:
patterns += get_static_routes(parse_vars(args.static_dirs))
static_dirs = parse_vars(args.static_dirs)
static_dirs['panel_dist'] = os.path.join(os.path.split(__file__)[0], 'dist')
patterns += get_static_routes()

if args.oauth_provider:
config.oauth_provider = args.oauth_provider
Expand Down
2 changes: 1 addition & 1 deletion panel/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def param_value_if_widget(arg):
ipy_param = param.parameterized_class(name, {'value': param.Parameter()})
ipywidget_classes[name] = ipy_param
ipy_inst = ipy_param(value=arg.value)
arg.observe(lambda event: ipy_inst.set_param(value=event['new']), 'value')
arg.observe(lambda event: ipy_inst.param.set_param(value=event['new']), 'value')
return ipy_inst.param.value
return arg

Expand Down
20 changes: 20 additions & 0 deletions panel/dist/post_require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if (window.ace != null) {
window._define_requirejs = window.define
window._require_requirejs = window.require
function custom_define (e, t, i) {
if (e.startsWith != null && e.startsWith("ace")) {
window._define_ace(e, t, i);
} else {
window._define_requirejs(e, t, i);
}
}
function custom_require (e, t, i, r) {
if (e.length && e[0].startsWith("ace")) {
window._require_ace(e, t, i, r);
} else {
window._require_requirejs(e, t, i, r);
}
}
window.define = custom_define
window.require = custom_require
}
7 changes: 7 additions & 0 deletions panel/dist/pre_require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if (window.ace != null) {
ace.config.set('basePath', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/')
window._require_ace = window.require
window._define_ace = window.define
delete window.require
delete window.define
}
10 changes: 8 additions & 2 deletions panel/io/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def css_raw(self):
if not os.path.isfile(cssf):
continue
with open(cssf) as f:
raw.append(f.read())
css_txt = f.read()
if css_txt not in raw:
raw.append(css_txt)
return raw + config.raw_css

def js_files(self):
Expand All @@ -37,14 +39,18 @@ def js_files(self):
require_index = [i for i, jsf in enumerate(js_files) if 'require' in jsf]
if require_index:
requirejs = js_files.pop(require_index[0])
if any('ace' in jsf for jsf in js_files):
js_files.append('/panel_dist/pre_require.js')
js_files.append(requirejs)
if any('ace' in jsf for jsf in js_files):
js_files.append('/panel_dist/post_require.js')
return js_files

def css_files(self):
from ..config import config
files = super(Resources, self).css_files
for cssf in config.css_files:
if os.path.isfile(cssf):
if os.path.isfile(cssf) or cssf in files:
continue
files.append(cssf)
return files
Expand Down
5 changes: 4 additions & 1 deletion panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def unlocked():
on current sessions.
"""
curdoc = state.curdoc
if curdoc is None or curdoc.session_context is None:
if curdoc is None or curdoc.session_context is None or curdoc.session_context.session is None:
yield
return
connections = curdoc.session_context.session._subscribed_connections
Expand Down Expand Up @@ -295,6 +295,9 @@ def get_server(panel, port=0, address=None, websocket_origin=None,
else:
apps = {'/': partial(_eval_panel, panel, server_id, title, location)}

dist_dir = os.path.join(os.path.split(os.path.dirname(__file__))[0], 'dist')
static_dirs = dict(static_dirs, panel_dist=dist_dir)

extra_patterns += get_static_routes(static_dirs)

opts = dict(kwargs)
Expand Down
6 changes: 5 additions & 1 deletion panel/layout/accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def _get_objects(self, model, old_objects, doc, root, comm=None):
else:
card = Card(
pane, title=name, css_classes=['accordion'],
header_css_classes=['accordion-header']
header_css_classes=['accordion-header'],
margin=self.margin
)
self._panels[id(pane)] = card
card.param.set_param(**params)
Expand All @@ -96,6 +97,7 @@ def _get_objects(self, model, old_objects, doc, root, comm=None):

new_models.append(panel)
self._update_cards()
self._update_active()
return new_models

def _cleanup(self, root):
Expand All @@ -114,6 +116,8 @@ def _apply_style(self, i):

def _update_active(self, *events):
for i, pane in enumerate(self.objects):
if id(pane) not in self._panels:
continue
self._panels[id(pane)].collapsed = i not in self.active

def _update_cards(self, *events):
Expand Down
5 changes: 3 additions & 2 deletions panel/layout/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class Card(Column):
_rename = dict(Column._rename, title=None, header=None, title_css_classes=None)

def __init__(self, *objects, **params):
self._header_layout = Row(css_classes=['card-header-row'])
self._header_layout = Row(css_classes=['card-header-row'],
sizing_mode='stretch_width')
super(Card, self).__init__(*objects, **params)
self.param.watch(self._update_header, ['title', 'header', 'title_css_classes'])
self._update_header()
Expand All @@ -73,7 +74,7 @@ def _process_param_change(self, params):
def _update_header(self, *events):
from ..pane import HTML, panel
if self.header is None:
item = HTML('%s' % (self.title or "​"), css_classes=self.title_css_classes)
item = HTML('%s' % (self.title or "​"), css_classes=self.title_css_classes, sizing_mode='stretch_width')
else:
item = panel(self.header)
self._header_layout[:] = [item]
Expand Down
3 changes: 2 additions & 1 deletion panel/layout/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ def _get_objects(self, model, old_objects, doc, root, comm=None):
properties['height'] = h*height
elif 'height' in self.sizing_mode:
properties['width'] = w*width
obj.param.set_param(**properties)
obj.param.set_param(**{k: v for k, v in properties.items()
if not obj.param[k].readonly})

if obj in old_objects:
child, _ = obj._models[root.ref['id']]
Expand Down
2 changes: 1 addition & 1 deletion panel/template/bootstrap/bootstrap.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends base %}

<!-- goes in body -->
{% block postamble %}
{% block preamble %}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
Expand Down
4 changes: 2 additions & 2 deletions panel/template/golden/golden.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% extends base %}

<!-- goes in body -->
{% block postamble %}
{% block preamble %}
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="https://golden-layout.com/files/latest/js/goldenlayout.js"></script>
<link type="text/css" rel="stylesheet" href="https://golden-layout.com/files/latest/css/goldenlayout-base.css" />
{% endblock %}
{% endblock %}

<!-- goes in body -->
{% block contents %}
Expand Down
2 changes: 1 addition & 1 deletion panel/template/material/material.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends base %}

<!-- goes in body -->
{% block postamble %}
{% block preamble %}
<link href="https://unpkg.com/material-components-web@v4.0.0/dist/material-components-web.min.css" rel="stylesheet">
<script src="https://unpkg.com/material-components-web@v4.0.0/dist/material-components-web.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
Expand Down