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

Only run preprocessors once on Templates #1703

Merged
merged 1 commit into from
Oct 27, 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/pane/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def clone(self, object=None, **params):
object = old_object
return type(self)(object, **params)

def get_root(self, doc=None, comm=None):
def get_root(self, doc=None, comm=None, preprocess=True):
"""
Returns the root model and applies pre-processing hooks

Expand All @@ -245,6 +245,8 @@ def get_root(self, doc=None, comm=None):
Bokeh document the bokeh model will be attached to.
comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
preprocess: boolean (default=True)
Whether to run preprocessing hooks

Returns
-------
Expand All @@ -255,7 +257,8 @@ def get_root(self, doc=None, comm=None):
root = self._get_model(doc, comm=comm)
else:
root = self.layout._get_model(doc, comm=comm)
self._preprocess(root)
if preprocess:
self._preprocess(root)
ref = root.ref['id']
state._views[ref] = (self, root, doc, comm)
return root
Expand Down
6 changes: 4 additions & 2 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def select(self, selector=None):
"""
return super().select(selector) + self.layout.select(selector)

def get_root(self, doc=None, comm=None):
def get_root(self, doc=None, comm=None, preprocess=True):
"""
Returns the root model and applies pre-processing hooks

Expand All @@ -590,13 +590,15 @@ def get_root(self, doc=None, comm=None):
Bokeh document the bokeh model will be attached to.
comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
preprocess: boolean (default=True)
Whether to run preprocessing hooks

Returns
-------
Returns the bokeh model corresponding to this panel object
"""
doc = init_doc(doc)
root = self.layout.get_root(doc, comm)
root = self.layout.get_root(doc, comm, preprocess)
ref = root.ref['id']
self._models[ref] = (root, None)
state._views[ref] = (self, root, doc, comm)
Expand Down
2 changes: 1 addition & 1 deletion panel/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _init_doc(self, doc=None, comm=None, title=None, notebook=False, location=Tr
for name, (obj, tags) in self._render_items.items():
if self._apply_hooks not in obj._hooks:
obj._hooks.append(self._apply_hooks)
model = obj.get_root(doc, comm)
model = obj.get_root(doc, comm, preprocess=False)
mref = model.ref['id']
doc.on_session_destroyed(obj._server_destroy)
for sub in obj.select(Viewable):
Expand Down
7 changes: 5 additions & 2 deletions panel/viewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def _server_destroy(self, session_context):
loc._cleanup(root)
del state._locations[doc]

def get_root(self, doc=None, comm=None):
def get_root(self, doc=None, comm=None, preprocess=True):
"""
Returns the root model and applies pre-processing hooks

Expand All @@ -471,14 +471,17 @@ def get_root(self, doc=None, comm=None):
Bokeh document the bokeh model will be attached to.
comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
preprocess: boolean (default=True)
Whether to run preprocessing hooks

Returns
-------
Returns the bokeh model corresponding to this panel object
"""
doc = init_doc(doc)
root = self._get_model(doc, comm=comm)
self._preprocess(root)
if preprocess:
self._preprocess(root)
ref = root.ref['id']
state._views[ref] = (self, root, doc, comm)
return root
Expand Down