Skip to content

Commit

Permalink
Add entry point for observable visualizations
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Oct 3, 2024
1 parent 3cf85a4 commit c40bf5d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
<%inherit file="visualization_base.mako"/>

## Create a container, attach data and import script file
<%def name="get_body()">
<%
from markupsafe import escape
## Collect incoming data
data_incoming = {
"root": h.url_for("/"),
"visualization_id": visualization_id,
"visualization_name": visualization_name,
"visualization_plugin": visualization_plugin,
"visualization_title": escape(title),
"visualization_config": config }
## Load script source
script_src = script_attributes.get("src")
%>
## Create container and initialize notebook
<div id="app" data-incoming='${h.dumps(data_incoming)}'></div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@observablehq/inspector@5/dist/inspector.css">
<script type="module">
import {Runtime, Inspector} from "https://cdn.jsdelivr.net/npm/@observablehq/runtime@5/dist/runtime.js";
import define from "https://api.observablehq.com/d/${script_src}";
new Runtime().module(define, Inspector.into("#app"));
</script>
</%def>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE visualization SYSTEM "../../visualization.dtd">
<visualization name="Example: Observable" embeddable="false">
<description>Welcome to the Observable Example Plugin.</description>
<data_sources>
<data_source>
<model_class>HistoryDatasetAssociation</model_class>
<test test_attr="ext" result_type="datatype">csv</test>
<to_param param_attr="id">dataset_id</to_param>
</data_source>
</data_sources>
<params>
<param type="dataset" var_name_in_template="hda" required="true">dataset_id</param>
</params>
<entry_point entry_point_type="observable" src="[email protected]?v=3" />
</visualization>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/galaxy/visualization/plugins/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class VisualizationsConfigParser:
"""

#: what are the allowed 'entry_point_type' for entry_point elements
ALLOWED_ENTRY_POINT_TYPES = ["mako", "html", "script", "chart"]
ALLOWED_ENTRY_POINT_TYPES = ["mako", "html", "script", "chart", "observable"]
#: what are the allowed href targets when clicking on a visualization anchor
VALID_RENDER_TARGETS = ["galaxy_main", "_top", "_blank"]

Expand Down
3 changes: 3 additions & 0 deletions lib/galaxy/visualization/plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ class ChartVisualizationPlugin(ScriptVisualizationPlugin):
MAKO_TEMPLATE = "chart_entry_point.mako"


class ObservableVisualizationPlugin(ScriptVisualizationPlugin):
MAKO_TEMPLATE = "observable_entry_point.mako"

class StaticFileVisualizationPlugin(VisualizationPlugin):
"""
A visualization plugin that starts by loading a static html file defined in
Expand Down
3 changes: 3 additions & 0 deletions lib/galaxy/visualization/plugins/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def _build_plugin(self, plugin_name, plugin_path, config):
# from a static file (html, etc)
elif config["entry_point"]["type"] == "html":
plugin_class = vis_plugins.StaticFileVisualizationPlugin
# from an observable notebook
elif config["entry_point"]["type"] == "observable":
plugin_class = vis_plugins.ObservableVisualizationPlugin
return plugin_class(
self.app(),
plugin_path,
Expand Down

0 comments on commit c40bf5d

Please sign in to comment.