Skip to content

Instantly share code, notes, and snippets.

@alonsosilvaallende
Created December 9, 2023 07:52
Show Gist options
  • Save alonsosilvaallende/20d80c711cb1f92aeab9baf4dd1eff0f to your computer and use it in GitHub Desktop.
Save alonsosilvaallende/20d80c711cb1f92aeab9baf4dd1eff0f to your computer and use it in GitHub Desktop.
Asyncio-Solara.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyOscEshCmLzR674lm3LaNC6",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"94df23d18b654e989feba93280f5b3ce": {
"model_module": "jupyter-vue",
"model_name": "HtmlModel",
"model_module_version": "^1.10.1",
"state": {
"_dom_classes": [],
"_events": [],
"_jupyter_vue": "IPY_MODEL_444db3f7fba14680a19aead20caa867b",
"_model_module": "jupyter-vue",
"_model_module_version": "^1.10.1",
"_model_name": "HtmlModel",
"_view_count": null,
"_view_module": "jupyter-vue",
"_view_module_version": "^1.10.1",
"_view_name": "VueView",
"attributes": {},
"children": [],
"class_": null,
"layout": null,
"slot": null,
"style_": "display: none",
"tag": "span",
"v_model": "!!disabled!!",
"v_on": null,
"v_slots": []
}
},
"f0981b274731471a8052d36161a6478f": {
"model_module": "@jupyter-widgets/controls",
"model_name": "VBoxModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "VBoxModel",
"_view_count": 1,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "VBoxView",
"box_style": "",
"children": [
"IPY_MODEL_712692543b8646f4ab217d725c4923f4"
],
"layout": "IPY_MODEL_6909f6c99f6b4c7ea4e2abe953dd2003"
}
},
"712692543b8646f4ab217d725c4923f4": {
"model_module": "jupyter-vuetify",
"model_name": "HtmlModel",
"model_module_version": "^1.8.10",
"state": {
"_dom_classes": [],
"_events": [],
"_jupyter_vue": "IPY_MODEL_444db3f7fba14680a19aead20caa867b",
"_model_module": "jupyter-vuetify",
"_model_module_version": "^1.8.10",
"_model_name": "HtmlModel",
"_view_count": null,
"_view_module": "jupyter-vuetify",
"_view_module_version": "^1.8.10",
"_view_name": "VuetifyView",
"attributes": {},
"children": [
"IPY_MODEL_0dcfc6a739ab47c3b470098fc195546a"
],
"class_": null,
"layout": null,
"slot": null,
"style_": null,
"tag": "div",
"v_model": "!!disabled!!",
"v_on": null,
"v_slots": []
}
},
"6909f6c99f6b4c7ea4e2abe953dd2003": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"0dcfc6a739ab47c3b470098fc195546a": {
"model_module": "jupyter-vuetify",
"model_name": "RowModel",
"model_module_version": "^1.8.5",
"state": {
"_dom_classes": [],
"_events": [],
"_jupyter_vue": "IPY_MODEL_444db3f7fba14680a19aead20caa867b",
"_metadata": null,
"_model_module": "jupyter-vuetify",
"_model_module_version": "^1.8.5",
"_model_name": "RowModel",
"_view_count": null,
"_view_module": "jupyter-vuetify",
"_view_module_version": "^1.8.5",
"_view_name": "VuetifyView",
"align": null,
"align_content": null,
"align_content_lg": null,
"align_content_md": null,
"align_content_sm": null,
"align_content_xl": null,
"align_lg": null,
"align_md": null,
"align_sm": null,
"align_xl": null,
"attributes": {},
"children": [
"IPY_MODEL_ab3a48c6ab0e4264a0e8f20d07556aa9"
],
"class_": "solara-content-main",
"dense": null,
"justify": null,
"justify_lg": null,
"justify_md": null,
"justify_sm": null,
"justify_xl": null,
"layout": null,
"no_gutters": false,
"slot": null,
"style_": null,
"tag": null,
"v_model": "!!disabled!!",
"v_on": null,
"v_slots": []
}
},
"ab3a48c6ab0e4264a0e8f20d07556aa9": {
"model_module": "jupyter-vuetify",
"model_name": "ColModel",
"model_module_version": "^1.8.5",
"state": {
"_dom_classes": [],
"_events": [],
"_jupyter_vue": "IPY_MODEL_444db3f7fba14680a19aead20caa867b",
"_metadata": null,
"_model_module": "jupyter-vuetify",
"_model_module_version": "^1.8.5",
"_model_name": "ColModel",
"_view_count": null,
"_view_module": "jupyter-vuetify",
"_view_module_version": "^1.8.5",
"_view_name": "VuetifyView",
"align_self": null,
"attributes": {},
"children": [
"IPY_MODEL_910ac670be9a400e81b6b34ff02e0d31"
],
"class_": null,
"cols": 12,
"layout": null,
"lg": null,
"md": null,
"offset": null,
"offset_lg": null,
"offset_md": null,
"offset_sm": null,
"offset_xl": null,
"order": null,
"order_lg": null,
"order_md": null,
"order_sm": null,
"order_xl": null,
"slot": null,
"sm": null,
"style_": null,
"tag": null,
"v_model": "!!disabled!!",
"v_on": null,
"v_slots": [],
"xl": null
}
},
"910ac670be9a400e81b6b34ff02e0d31": {
"model_module": "jupyter-vuetify",
"model_name": "SheetModel",
"model_module_version": "^1.8.5",
"state": {
"_dom_classes": [],
"_events": [],
"_jupyter_vue": "IPY_MODEL_444db3f7fba14680a19aead20caa867b",
"_metadata": null,
"_model_module": "jupyter-vuetify",
"_model_module_version": "^1.8.5",
"_model_name": "SheetModel",
"_view_count": null,
"_view_module": "jupyter-vuetify",
"_view_module_version": "^1.8.5",
"_view_name": "VuetifyView",
"attributes": {},
"children": [
"IPY_MODEL_538c4b942b454b31a072222a9ae2f322",
"IPY_MODEL_2caa44810d7341deb48b21e351145edf"
],
"class_": "d-flex ma-0",
"color": null,
"dark": null,
"elevation": 0,
"height": null,
"layout": null,
"light": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"slot": null,
"style_": "flex-direction: column; align-items: stretch; row-gap: 12px;;",
"tag": null,
"tile": null,
"v_model": "!!disabled!!",
"v_on": null,
"v_slots": [],
"width": null
}
},
"538c4b942b454b31a072222a9ae2f322": {
"model_module": "jupyter-vuetify",
"model_name": "VuetifyTemplateModel",
"model_module_version": "^1.8.10",
"state": {
"_component_instances": [],
"_dom_classes": [],
"_jupyter_vue": "IPY_MODEL_444db3f7fba14680a19aead20caa867b",
"_model_module": "jupyter-vuetify",
"_model_module_version": "^1.8.10",
"_model_name": "VuetifyTemplateModel",
"_view_count": null,
"_view_module": "jupyter-vuetify",
"_view_module_version": "^1.8.10",
"_view_name": "VuetifyView",
"components": null,
"css": null,
"data": null,
"events": [],
"layout": "IPY_MODEL_8a59c035711949f28c34e5d275cce126",
"methods": null,
"template": "\n<template>\n <div class=\"solara-markdown rendered_html jp-RenderedHTMLCommon\" style=\"\"><p>Hello!</p></div>\n</template>\n\n<script>\nmodule.exports = {\n mounted() {\n if(window.mermaid)\n mermaid.init()\n if(window.MathJax && MathJax.Hub) {\n MathJax.Hub.Queue(['Typeset', MathJax.Hub, this.$el]);\n }\n this.$el.querySelectorAll(\"a\").forEach(a => this.setupRouter(a))\n window.md = this.$el\n },\n methods: {\n setupRouter(a) {\n let href = a.attributes['href'].value;\n if(href.startsWith(\"./\")) {\n // TODO: should we really do this?\n href = location.pathname + href.substr(1);\n a.attributes['href'].href = href;\n // console.log(\"change href to\", href);\n }\n if(href.startsWith(\"./\") || href.startsWith(\"/\")) {\n // console.log(\"connect link with href=\", href, \"to router\")\n a.onclick = e => {\n console.log(\"clicked\", href)\n if(href.startsWith(\"./\")) {\n solara.router.push(href);\n } else {\n solara.router.push(href);\n }\n e.preventDefault()\n }\n } else if(href.startsWith(\"#\")) {\n // console.log(\"connect anchor with href=\", href, \"to custom javascript due to using <base>\")\n href = location.pathname + href;\n a.attributes['href'].value = href;\n } else {\n console.log(\"href\", href, \"is not a local link\")\n }\n }\n },\n updated() {\n // if the html gets update, re-run mermaid\n if(window.mermaid)\n mermaid.init()\n if(window.MathJax && MathJax.Hub) {\n MathJax.Hub.Queue(['Typeset', MathJax.Hub, this.$el]);\n }\n }\n}\n</script>\n "
}
},
"2caa44810d7341deb48b21e351145edf": {
"model_module": "jupyter-vuetify",
"model_name": "HtmlModel",
"model_module_version": "^1.8.10",
"state": {
"_dom_classes": [],
"_events": [],
"_jupyter_vue": "IPY_MODEL_444db3f7fba14680a19aead20caa867b",
"_model_module": "jupyter-vuetify",
"_model_module_version": "^1.8.10",
"_model_name": "HtmlModel",
"_view_count": null,
"_view_module": "jupyter-vuetify",
"_view_module_version": "^1.8.10",
"_view_name": "VuetifyView",
"attributes": {
"src": "https://solara.dev/static/public/success.html?check=widget",
"width": "0px",
"height": "0px"
},
"children": [],
"class_": null,
"layout": null,
"slot": null,
"style_": "display: none;",
"tag": "iframe",
"v_model": "!!disabled!!",
"v_on": null,
"v_slots": []
}
},
"8a59c035711949f28c34e5d275cce126": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
}
}
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/alonsosilvaallende/20d80c711cb1f92aeab9baf4dd1eff0f/asyncio-solara.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"!pip install -q solara"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "0Fzo3iwRBIU6",
"outputId": "e4f3631d-a8d6-4388-e960-dce18009788c"
},
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m15.6/15.6 MB\u001b[0m \u001b[31m55.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.7/2.7 MB\u001b[0m \u001b[31m70.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m11.7/11.7 MB\u001b[0m \u001b[31m89.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m105.9/105.9 kB\u001b[0m \u001b[31m10.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m241.1/241.1 kB\u001b[0m \u001b[31m22.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m107.4/107.4 kB\u001b[0m \u001b[31m10.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m70.1/70.1 kB\u001b[0m \u001b[31m6.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m59.7/59.7 kB\u001b[0m \u001b[31m6.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m82.1/82.1 kB\u001b[0m \u001b[31m8.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m61.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.2/130.2 kB\u001b[0m \u001b[31m12.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m6.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m64.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m133.5/133.5 kB\u001b[0m \u001b[31m15.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
"lida 0.0.10 requires fastapi, which is not installed.\n",
"lida 0.0.10 requires kaleido, which is not installed.\n",
"lida 0.0.10 requires python-multipart, which is not installed.\u001b[0m\u001b[31m\n",
"\u001b[0m"
]
}
]
},
{
"cell_type": "code",
"source": [
"import nest_asyncio\n",
"nest_asyncio.apply()"
],
"metadata": {
"id": "aBfn3zGOCIWA"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import asyncio\n",
"import solara"
],
"metadata": {
"id": "aUEN8F8rBZhF"
},
"execution_count": 3,
"outputs": []
},
{
"cell_type": "code",
"source": [
"@solara.component\n",
"def Page():\n",
" async def main():\n",
" print(\"Hello World!\")\n",
"\n",
" asyncio.run(main())\n",
" solara.Markdown(\"Hello!\")\n",
"Page()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 96,
"referenced_widgets": [
"94df23d18b654e989feba93280f5b3ce",
"f0981b274731471a8052d36161a6478f",
"712692543b8646f4ab217d725c4923f4",
"6909f6c99f6b4c7ea4e2abe953dd2003",
"0dcfc6a739ab47c3b470098fc195546a",
"ab3a48c6ab0e4264a0e8f20d07556aa9",
"910ac670be9a400e81b6b34ff02e0d31",
"538c4b942b454b31a072222a9ae2f322",
"2caa44810d7341deb48b21e351145edf",
"8a59c035711949f28c34e5d275cce126"
]
},
"id": "kHDSG8YRBHO_",
"outputId": "078f2ec7-76e3-4b94-c070-93df53eb7df1"
},
"execution_count": 4,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"Html(layout=None, style_='display: none', tag='span')"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "94df23d18b654e989feba93280f5b3ce"
}
},
"metadata": {
"application/vnd.jupyter.widget-view+json": {
"colab": {
"custom_widget_manager": {
"url": "https://ssl.gstatic.com/colaboratory-static/widgets/colab-cdn-widget-manager/b3e629b1971e1542/manager.min.js"
}
}
}
}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Hello World!\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Javascript object>"
],
"application/javascript": [
"\n",
"const prevIframe = document.getElementById(\"solara-jupyter-check\");\n",
"if(prevIframe)\n",
" prevIframe.remove();\n",
"const iframe = document.createElement('iframe')\n",
"iframe.setAttribute(\"src\", \"https://solara.dev/static/public/success.html?check=purejs\");\n",
"iframe.style.width = \"0px\";\n",
"iframe.style.height = \"0px\";\n",
"iframe.style.display = \"none\";\n",
"iframe.id = \"solara-jupyter-check\";\n",
"document.body.appendChild(iframe);\n",
" "
]
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"Cannot show ipywidgets in text"
],
"text/html": [
"Cannot show widget. You probably want to rerun the code cell above (<i>Click in the code cell, and press Shift+Enter <kbd>⇧</kbd>+<kbd>↩</kbd></i>)."
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "f0981b274731471a8052d36161a6478f"
}
},
"metadata": {
"application/vnd.jupyter.widget-view+json": {
"colab": {
"custom_widget_manager": {
"url": "https://ssl.gstatic.com/colaboratory-static/widgets/colab-cdn-widget-manager/b3e629b1971e1542/manager.min.js"
}
}
}
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment