Skip to content

Instantly share code, notes, and snippets.

@oeway
Created August 3, 2023 02:12

Revisions

  1. oeway created this gist Aug 3, 2023.
    68 changes: 68 additions & 0 deletions stlite-demo.imjoy.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    <docs lang="markdown">
    [TODO: write documentation for this plugin.]
    </docs>

    <config lang="json">
    {
    "name": "stlite Demo",
    "type": "window",
    "tags": [],
    "ui": "",
    "version": "0.1.0",
    "cover": "",
    "description": "[TODO: describe this plugin with one sentence.]",
    "icon": "extension",
    "inputs": null,
    "outputs": null,
    "api_version": "0.1.8",
    "env": "",
    "permissions": [],
    "requirements": ["https://cdn.jsdelivr.net/npm/@stlite/mountable@0.34.0/build/stlite.css", "https://cdn.jsdelivr.net/npm/@stlite/mountable@0.34.0/build/stlite.js"],
    "dependencies": [],
    "defaults": {"w": 20, "h": 10}
    }
    </config>

    <script lang="javascript">
    class ImJoyPlugin {
    async setup() {
    api.log('initialized')
    }

    async run(ctx) {
    stlite.mount(
    {
    requirements: ["matplotlib"], // Packages to install
    entrypoint: "streamlit_app.py", // The target file of the `streamlit run` command
    files: {
    "streamlit_app.py": `
    import streamlit as st
    import matplotlib.pyplot as plt
    import numpy as np
    size = st.slider("Sample size", 100, 1000)
    arr = np.random.normal(1, 1, size=size)
    fig, ax = plt.subplots()
    ax.hist(arr, bins=20)
    st.pyplot(fig)
    `,
    },
    },
    document.getElementById("root")
    );
    }
    }

    api.export(new ImJoyPlugin())
    </script>

    <window lang="html">
    <div id="root">
    </div>
    </window>

    <style lang="css">

    </style>