Commit
·
4ec8d4b
1
Parent(s):
fdd9855
Delete app.js
Browse files
app.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
| 1 |
-
importScripts("https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.js");
|
| 2 |
-
|
| 3 |
-
function sendPatch(patch, buffers, msg_id) {
|
| 4 |
-
self.postMessage({
|
| 5 |
-
type: 'patch',
|
| 6 |
-
patch: patch,
|
| 7 |
-
buffers: buffers
|
| 8 |
-
})
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
async function startApplication() {
|
| 12 |
-
console.log("Loading pyodide!");
|
| 13 |
-
self.postMessage({type: 'status', msg: 'Loading pyodide'})
|
| 14 |
-
self.pyodide = await loadPyodide();
|
| 15 |
-
self.pyodide.globals.set("sendPatch", sendPatch);
|
| 16 |
-
console.log("Loaded!");
|
| 17 |
-
await self.pyodide.loadPackage("micropip");
|
| 18 |
-
const env_spec = ['https://cdn.holoviz.org/panel/wheels/bokeh-3.3.2-py3-none-any.whl', 'https://cdn.holoviz.org/panel/1.3.6/dist/wheels/panel-1.3.6-py3-none-any.whl', 'pyodide-http==0.2.1', 'hvplot', 'pandas']
|
| 19 |
-
for (const pkg of env_spec) {
|
| 20 |
-
let pkg_name;
|
| 21 |
-
if (pkg.endsWith('.whl')) {
|
| 22 |
-
pkg_name = pkg.split('/').slice(-1)[0].split('-')[0]
|
| 23 |
-
} else {
|
| 24 |
-
pkg_name = pkg
|
| 25 |
-
}
|
| 26 |
-
self.postMessage({type: 'status', msg: `Installing ${pkg_name}`})
|
| 27 |
-
try {
|
| 28 |
-
await self.pyodide.runPythonAsync(`
|
| 29 |
-
import micropip
|
| 30 |
-
await micropip.install('${pkg}');
|
| 31 |
-
`);
|
| 32 |
-
} catch(e) {
|
| 33 |
-
console.log(e)
|
| 34 |
-
self.postMessage({
|
| 35 |
-
type: 'status',
|
| 36 |
-
msg: `Error while installing ${pkg_name}`
|
| 37 |
-
});
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
console.log("Packages loaded!");
|
| 41 |
-
self.postMessage({type: 'status', msg: 'Executing code'})
|
| 42 |
-
const code = `
|
| 43 |
-
|
| 44 |
-
import asyncio
|
| 45 |
-
|
| 46 |
-
from panel.io.pyodide import init_doc, write_doc
|
| 47 |
-
|
| 48 |
-
init_doc()
|
| 49 |
-
|
| 50 |
-
"""The purpose of this app is to test that a **multi-page Dashboard Layout** similar to the
|
| 51 |
-
[bootstrap dashboard template](https://getbootstrap.com/docs/4.3/examples/dashboard/)
|
| 52 |
-
from [getboostrap.com](https://getbootstrap.com/) can be implemented in
|
| 53 |
-
[Panel](https://panel.pyviz.org/).
|
| 54 |
-
"""
|
| 55 |
-
import hvplot.pandas # pylint: disable=unused-import
|
| 56 |
-
import pandas as pd
|
| 57 |
-
import panel as pn
|
| 58 |
-
|
| 59 |
-
BOOTSTRAP_DASHBOARD_CHART_URL="https://awesomepanel.blob.core.windows.net/resources/bootstrap_dashboard/bootstrap_dashboard_chart.csv"
|
| 60 |
-
BOOTSTRAP_DASHBOARD_TABLE_URL="https://awesomepanel.blob.core.windows.net/resources/bootstrap_dashboard/bootstrap_dashboard_table.csv"
|
| 61 |
-
|
| 62 |
-
COLOR="#0072B5"
|
| 63 |
-
|
| 64 |
-
@pn.cache
|
| 65 |
-
def _get_chart_data():
|
| 66 |
-
return pd.read_csv(BOOTSTRAP_DASHBOARD_CHART_URL)
|
| 67 |
-
|
| 68 |
-
@pn.cache
|
| 69 |
-
def _get_table_data():
|
| 70 |
-
return pd.read_csv(BOOTSTRAP_DASHBOARD_TABLE_URL)
|
| 71 |
-
|
| 72 |
-
def _holoviews_chart():
|
| 73 |
-
"""## Dashboard Orders Chart generated by HoloViews"""
|
| 74 |
-
data = _get_chart_data()
|
| 75 |
-
line_plot = data.hvplot.line(
|
| 76 |
-
x="Day",
|
| 77 |
-
y="Orders",
|
| 78 |
-
height=500,
|
| 79 |
-
line_color=COLOR,
|
| 80 |
-
line_width=6,
|
| 81 |
-
)
|
| 82 |
-
scatter_plot = data.hvplot.scatter(x="Day", y="Orders", height=300,).opts(
|
| 83 |
-
marker="o",
|
| 84 |
-
size=10,
|
| 85 |
-
color=COLOR,
|
| 86 |
-
)
|
| 87 |
-
fig = line_plot * scatter_plot
|
| 88 |
-
gridstyle = {
|
| 89 |
-
"grid_line_color": "black",
|
| 90 |
-
"grid_line_width": 0.1,
|
| 91 |
-
}
|
| 92 |
-
fig = fig.opts(
|
| 93 |
-
responsive=True,
|
| 94 |
-
toolbar=None,
|
| 95 |
-
yticks=list(
|
| 96 |
-
range(
|
| 97 |
-
12000,
|
| 98 |
-
26000,
|
| 99 |
-
2000,
|
| 100 |
-
)
|
| 101 |
-
),
|
| 102 |
-
ylim=(
|
| 103 |
-
12000,
|
| 104 |
-
26000,
|
| 105 |
-
),
|
| 106 |
-
gridstyle=gridstyle,
|
| 107 |
-
show_grid=True,
|
| 108 |
-
)
|
| 109 |
-
return fig
|
| 110 |
-
|
| 111 |
-
app = pn.extension("tabulator", sizing_mode="stretch_width")
|
| 112 |
-
|
| 113 |
-
pn.template.FastListTemplate(
|
| 114 |
-
site="Awesome Panel", site_url="https://awesome-panel.org", title="Bootstrap Dashboard",
|
| 115 |
-
main=[
|
| 116 |
-
pn.Column(pn.pane.Markdown("## Dashboard"), _holoviews_chart()),
|
| 117 |
-
pn.Column(pn.pane.Markdown("## Section Title"), pn.widgets.Tabulator(_get_table_data(), layout='fit_data_stretch')),
|
| 118 |
-
], main_max_width="800px", main_layout=None,
|
| 119 |
-
).servable("bootstrap_dashboard.html")
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
await write_doc()
|
| 124 |
-
`
|
| 125 |
-
|
| 126 |
-
try {
|
| 127 |
-
const [docs_json, render_items, root_ids] = await self.pyodide.runPythonAsync(code)
|
| 128 |
-
self.postMessage({
|
| 129 |
-
type: 'render',
|
| 130 |
-
docs_json: docs_json,
|
| 131 |
-
render_items: render_items,
|
| 132 |
-
root_ids: root_ids
|
| 133 |
-
})
|
| 134 |
-
} catch(e) {
|
| 135 |
-
const traceback = `${e}`
|
| 136 |
-
const tblines = traceback.split('\n')
|
| 137 |
-
self.postMessage({
|
| 138 |
-
type: 'status',
|
| 139 |
-
msg: tblines[tblines.length-2]
|
| 140 |
-
});
|
| 141 |
-
throw e
|
| 142 |
-
}
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
self.onmessage = async (event) => {
|
| 146 |
-
const msg = event.data
|
| 147 |
-
if (msg.type === 'rendered') {
|
| 148 |
-
self.pyodide.runPythonAsync(`
|
| 149 |
-
from panel.io.state import state
|
| 150 |
-
from panel.io.pyodide import _link_docs_worker
|
| 151 |
-
|
| 152 |
-
_link_docs_worker(state.curdoc, sendPatch, setter='js')
|
| 153 |
-
`)
|
| 154 |
-
} else if (msg.type === 'patch') {
|
| 155 |
-
self.pyodide.globals.set('patch', msg.patch)
|
| 156 |
-
self.pyodide.runPythonAsync(`
|
| 157 |
-
state.curdoc.apply_json_patch(patch.to_py(), setter='js')
|
| 158 |
-
`)
|
| 159 |
-
self.postMessage({type: 'idle'})
|
| 160 |
-
} else if (msg.type === 'location') {
|
| 161 |
-
self.pyodide.globals.set('location', msg.location)
|
| 162 |
-
self.pyodide.runPythonAsync(`
|
| 163 |
-
import json
|
| 164 |
-
from panel.io.state import state
|
| 165 |
-
from panel.util import edit_readonly
|
| 166 |
-
if state.location:
|
| 167 |
-
loc_data = json.loads(location)
|
| 168 |
-
with edit_readonly(state.location):
|
| 169 |
-
state.location.param.update({
|
| 170 |
-
k: v for k, v in loc_data.items() if k in state.location.param
|
| 171 |
-
})
|
| 172 |
-
`)
|
| 173 |
-
}
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
startApplication()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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