solara-ui 1.45.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prefix/etc/jupyter/jupyter_notebook_config.d/solara.json +7 -0
- prefix/etc/jupyter/jupyter_server_config.d/solara.json +7 -0
- solara/__init__.py +124 -0
- solara/__main__.py +765 -0
- solara/_stores.py +297 -0
- solara/alias.py +6 -0
- solara/autorouting.py +555 -0
- solara/cache.py +305 -0
- solara/checks.html +71 -0
- solara/checks.py +227 -0
- solara/comm.py +28 -0
- solara/components/__init__.py +77 -0
- solara/components/alert.py +155 -0
- solara/components/applayout.py +397 -0
- solara/components/button.py +85 -0
- solara/components/card.py +87 -0
- solara/components/checkbox.py +50 -0
- solara/components/code_highlight_css.py +11 -0
- solara/components/code_highlight_css.vue +63 -0
- solara/components/columns.py +159 -0
- solara/components/component_vue.py +134 -0
- solara/components/cross_filter.py +335 -0
- solara/components/dataframe.py +546 -0
- solara/components/datatable.py +214 -0
- solara/components/datatable.vue +175 -0
- solara/components/details.py +56 -0
- solara/components/download.vue +35 -0
- solara/components/echarts.py +86 -0
- solara/components/echarts.vue +139 -0
- solara/components/figure_altair.py +39 -0
- solara/components/file_browser.py +181 -0
- solara/components/file_download.py +199 -0
- solara/components/file_drop.py +159 -0
- solara/components/file_drop.vue +83 -0
- solara/components/file_list_widget.vue +78 -0
- solara/components/head.py +27 -0
- solara/components/head_tag.py +49 -0
- solara/components/head_tag.vue +60 -0
- solara/components/image.py +173 -0
- solara/components/input.py +456 -0
- solara/components/input_text_area.py +86 -0
- solara/components/link.py +55 -0
- solara/components/markdown.py +441 -0
- solara/components/markdown_editor.py +33 -0
- solara/components/markdown_editor.vue +359 -0
- solara/components/matplotlib.py +74 -0
- solara/components/meta.py +47 -0
- solara/components/misc.py +333 -0
- solara/components/pivot_table.py +258 -0
- solara/components/pivot_table.vue +158 -0
- solara/components/progress.py +47 -0
- solara/components/select.py +182 -0
- solara/components/select.vue +27 -0
- solara/components/slider.py +442 -0
- solara/components/slider_date.vue +56 -0
- solara/components/spinner-solara.vue +105 -0
- solara/components/spinner.py +45 -0
- solara/components/sql_code.py +41 -0
- solara/components/sql_code.vue +125 -0
- solara/components/style.py +105 -0
- solara/components/switch.py +71 -0
- solara/components/tab_navigation.py +37 -0
- solara/components/title.py +90 -0
- solara/components/title.vue +38 -0
- solara/components/togglebuttons.py +200 -0
- solara/components/tooltip.py +61 -0
- solara/core.py +42 -0
- solara/datatypes.py +143 -0
- solara/express.py +241 -0
- solara/hooks/__init__.py +4 -0
- solara/hooks/dataframe.py +99 -0
- solara/hooks/misc.py +263 -0
- solara/hooks/use_reactive.py +151 -0
- solara/hooks/use_thread.py +129 -0
- solara/kitchensink.py +8 -0
- solara/lab/__init__.py +34 -0
- solara/lab/components/__init__.py +7 -0
- solara/lab/components/chat.py +215 -0
- solara/lab/components/confirmation_dialog.py +163 -0
- solara/lab/components/cross_filter.py +7 -0
- solara/lab/components/input_date.py +339 -0
- solara/lab/components/input_time.py +133 -0
- solara/lab/components/menu.py +181 -0
- solara/lab/components/menu.vue +38 -0
- solara/lab/components/tabs.py +274 -0
- solara/lab/components/theming.py +98 -0
- solara/lab/components/theming.vue +72 -0
- solara/lab/hooks/__init__.py +0 -0
- solara/lab/hooks/dataframe.py +2 -0
- solara/lab/toestand.py +3 -0
- solara/lab/utils/__init__.py +2 -0
- solara/lab/utils/cookies.py +5 -0
- solara/lab/utils/dataframe.py +165 -0
- solara/lab/utils/headers.py +5 -0
- solara/layout.py +44 -0
- solara/lifecycle.py +46 -0
- solara/minisettings.py +141 -0
- solara/py.typed +0 -0
- solara/reactive.py +99 -0
- solara/routing.py +268 -0
- solara/scope/__init__.py +88 -0
- solara/scope/types.py +55 -0
- solara/server/__init__.py +0 -0
- solara/server/app.py +527 -0
- solara/server/assets/custom.css +1 -0
- solara/server/assets/custom.js +1 -0
- solara/server/assets/favicon.png +0 -0
- solara/server/assets/favicon.svg +5 -0
- solara/server/assets/style.css +1681 -0
- solara/server/assets/theme-dark.css +437 -0
- solara/server/assets/theme-light.css +420 -0
- solara/server/assets/theme.js +3 -0
- solara/server/cdn_helper.py +91 -0
- solara/server/esm.py +71 -0
- solara/server/fastapi.py +5 -0
- solara/server/flask.py +297 -0
- solara/server/jupyter/__init__.py +2 -0
- solara/server/jupyter/cdn_handler.py +28 -0
- solara/server/jupyter/server_extension.py +40 -0
- solara/server/jupyter/solara.py +91 -0
- solara/server/jupytertools.py +46 -0
- solara/server/kernel.py +388 -0
- solara/server/kernel_context.py +467 -0
- solara/server/patch.py +564 -0
- solara/server/pyinstaller/__init__.py +9 -0
- solara/server/pyinstaller/hook-ipyreact.py +5 -0
- solara/server/pyinstaller/hook-ipyvuetify.py +5 -0
- solara/server/pyinstaller/hook-solara.py +9 -0
- solara/server/qt.py +113 -0
- solara/server/reload.py +251 -0
- solara/server/server.py +484 -0
- solara/server/settings.py +249 -0
- solara/server/shell.py +269 -0
- solara/server/starlette.py +770 -0
- solara/server/static/ansi.js +270 -0
- solara/server/static/highlight-dark.css +82 -0
- solara/server/static/highlight.css +43 -0
- solara/server/static/main-vuetify.js +272 -0
- solara/server/static/main.js +163 -0
- solara/server/static/solara_bootstrap.py +129 -0
- solara/server/static/sun.svg +23 -0
- solara/server/static/webworker.js +42 -0
- solara/server/telemetry.py +212 -0
- solara/server/templates/index.html.j2 +1 -0
- solara/server/templates/loader-plain.css +11 -0
- solara/server/templates/loader-plain.html +20 -0
- solara/server/templates/loader-solara.css +111 -0
- solara/server/templates/loader-solara.html +40 -0
- solara/server/templates/plain.html +82 -0
- solara/server/templates/solara.html.j2 +486 -0
- solara/server/threaded.py +84 -0
- solara/server/utils.py +44 -0
- solara/server/websocket.py +45 -0
- solara/settings.py +86 -0
- solara/tasks.py +893 -0
- solara/template/button.py +16 -0
- solara/template/markdown.py +42 -0
- solara/template/portal/.flake8 +6 -0
- solara/template/portal/.pre-commit-config.yaml +28 -0
- solara/template/portal/LICENSE +21 -0
- solara/template/portal/Procfile +7 -0
- solara/template/portal/mypy.ini +3 -0
- solara/template/portal/pyproject.toml +26 -0
- solara/template/portal/solara_portal/__init__.py +4 -0
- solara/template/portal/solara_portal/components/__init__.py +2 -0
- solara/template/portal/solara_portal/components/article.py +28 -0
- solara/template/portal/solara_portal/components/data.py +28 -0
- solara/template/portal/solara_portal/components/header.py +6 -0
- solara/template/portal/solara_portal/components/layout.py +6 -0
- solara/template/portal/solara_portal/content/articles/equis-in-vidi.md +85 -0
- solara/template/portal/solara_portal/content/articles/substiterat-vati.md +70 -0
- solara/template/portal/solara_portal/data.py +60 -0
- solara/template/portal/solara_portal/pages/__init__.py +67 -0
- solara/template/portal/solara_portal/pages/article/__init__.py +26 -0
- solara/template/portal/solara_portal/pages/tabular.py +29 -0
- solara/template/portal/solara_portal/pages/viz/__init__.py +70 -0
- solara/template/portal/solara_portal/pages/viz/overview.py +14 -0
- solara/test/__init__.py +0 -0
- solara/test/pytest_plugin.py +783 -0
- solara/toestand.py +998 -0
- solara/util.py +348 -0
- solara/validate_hooks.py +258 -0
- solara/website/__init__.py +0 -0
- solara/website/assets/custom.css +444 -0
- solara/website/assets/images/logo-small.png +0 -0
- solara/website/assets/images/logo.svg +17 -0
- solara/website/assets/images/logo_white.svg +50 -0
- solara/website/assets/theme.js +8 -0
- solara/website/components/__init__.py +5 -0
- solara/website/components/algolia.py +6 -0
- solara/website/components/algolia.vue +24 -0
- solara/website/components/algolia_api.vue +202 -0
- solara/website/components/breadcrumbs.py +28 -0
- solara/website/components/contact.py +144 -0
- solara/website/components/docs.py +143 -0
- solara/website/components/header.py +75 -0
- solara/website/components/mailchimp.py +12 -0
- solara/website/components/mailchimp.vue +47 -0
- solara/website/components/markdown.py +99 -0
- solara/website/components/markdown_nav.vue +34 -0
- solara/website/components/notebook.py +171 -0
- solara/website/components/sidebar.py +105 -0
- solara/website/pages/__init__.py +370 -0
- solara/website/pages/about/__init__.py +9 -0
- solara/website/pages/about/about.md +3 -0
- solara/website/pages/apps/__init__.py +16 -0
- solara/website/pages/apps/authorization/__init__.py +119 -0
- solara/website/pages/apps/authorization/admin.py +12 -0
- solara/website/pages/apps/authorization/users.py +12 -0
- solara/website/pages/apps/jupyter-dashboard-1.py +116 -0
- solara/website/pages/apps/layout-demo.py +40 -0
- solara/website/pages/apps/multipage/__init__.py +38 -0
- solara/website/pages/apps/multipage/page1.py +26 -0
- solara/website/pages/apps/multipage/page2.py +34 -0
- solara/website/pages/apps/scatter.py +136 -0
- solara/website/pages/apps/scrolling.py +63 -0
- solara/website/pages/apps/tutorial-streamlit.py +18 -0
- solara/website/pages/careers/__init__.py +27 -0
- solara/website/pages/changelog/__init__.py +10 -0
- solara/website/pages/changelog/changelog.md +372 -0
- solara/website/pages/contact/__init__.py +34 -0
- solara/website/pages/doc_use_download.py +85 -0
- solara/website/pages/documentation/__init__.py +90 -0
- solara/website/pages/documentation/advanced/__init__.py +9 -0
- solara/website/pages/documentation/advanced/content/00-overview.md +1 -0
- solara/website/pages/documentation/advanced/content/10-howto/00-overview.md +6 -0
- solara/website/pages/documentation/advanced/content/10-howto/10-multipage.md +196 -0
- solara/website/pages/documentation/advanced/content/10-howto/20-layout.md +125 -0
- solara/website/pages/documentation/advanced/content/10-howto/30-testing.md +417 -0
- solara/website/pages/documentation/advanced/content/10-howto/31-debugging.md +69 -0
- solara/website/pages/documentation/advanced/content/10-howto/40-embed.md +50 -0
- solara/website/pages/documentation/advanced/content/10-howto/50-ipywidget_libraries.md +124 -0
- solara/website/pages/documentation/advanced/content/15-reference/00-overview.md +3 -0
- solara/website/pages/documentation/advanced/content/15-reference/40-static_files.md +31 -0
- solara/website/pages/documentation/advanced/content/15-reference/41-asset-files.md +72 -0
- solara/website/pages/documentation/advanced/content/15-reference/60-static-site-generation.md +59 -0
- solara/website/pages/documentation/advanced/content/15-reference/70-search.md +34 -0
- solara/website/pages/documentation/advanced/content/15-reference/80-reloading.md +34 -0
- solara/website/pages/documentation/advanced/content/15-reference/90-notebook-support.md +7 -0
- solara/website/pages/documentation/advanced/content/15-reference/95-caching.md +148 -0
- solara/website/pages/documentation/advanced/content/20-understanding/00-introduction.md +10 -0
- solara/website/pages/documentation/advanced/content/20-understanding/05-ipywidgets.md +35 -0
- solara/website/pages/documentation/advanced/content/20-understanding/06-ipyvuetify.md +42 -0
- solara/website/pages/documentation/advanced/content/20-understanding/10-reacton.md +28 -0
- solara/website/pages/documentation/advanced/content/20-understanding/12-reacton-basics.md +108 -0
- solara/website/pages/documentation/advanced/content/20-understanding/15-anatomy.md +23 -0
- solara/website/pages/documentation/advanced/content/20-understanding/17-rules-of-hooks.md +192 -0
- solara/website/pages/documentation/advanced/content/20-understanding/18-containers.md +166 -0
- solara/website/pages/documentation/advanced/content/20-understanding/20-solara.md +18 -0
- solara/website/pages/documentation/advanced/content/20-understanding/40-routing.md +256 -0
- solara/website/pages/documentation/advanced/content/20-understanding/50-solara-server.md +108 -0
- solara/website/pages/documentation/advanced/content/20-understanding/60-voila.md +12 -0
- solara/website/pages/documentation/advanced/content/30-enterprise/00-overview.md +7 -0
- solara/website/pages/documentation/advanced/content/30-enterprise/10-oauth.md +187 -0
- solara/website/pages/documentation/advanced/content/40-development/00-overview.md +0 -0
- solara/website/pages/documentation/advanced/content/40-development/01-contribute.md +45 -0
- solara/website/pages/documentation/advanced/content/40-development/10-setup.md +76 -0
- solara/website/pages/documentation/api/__init__.py +19 -0
- solara/website/pages/documentation/api/cross_filter/__init__.py +9 -0
- solara/website/pages/documentation/api/cross_filter/cross_filter_dataframe.py +22 -0
- solara/website/pages/documentation/api/cross_filter/cross_filter_report.py +20 -0
- solara/website/pages/documentation/api/cross_filter/cross_filter_select.py +20 -0
- solara/website/pages/documentation/api/cross_filter/cross_filter_slider.py +20 -0
- solara/website/pages/documentation/api/hooks/__init__.py +9 -0
- solara/website/pages/documentation/api/hooks/use_cross_filter.py +23 -0
- solara/website/pages/documentation/api/hooks/use_dark_effective.py +12 -0
- solara/website/pages/documentation/api/hooks/use_effect.md +43 -0
- solara/website/pages/documentation/api/hooks/use_effect.py +9 -0
- solara/website/pages/documentation/api/hooks/use_exception.py +31 -0
- solara/website/pages/documentation/api/hooks/use_memo.md +16 -0
- solara/website/pages/documentation/api/hooks/use_memo.py +9 -0
- solara/website/pages/documentation/api/hooks/use_previous.py +30 -0
- solara/website/pages/documentation/api/hooks/use_reactive.py +16 -0
- solara/website/pages/documentation/api/hooks/use_state.py +10 -0
- solara/website/pages/documentation/api/hooks/use_state_or_update.py +66 -0
- solara/website/pages/documentation/api/hooks/use_thread.md +64 -0
- solara/website/pages/documentation/api/hooks/use_thread.py +42 -0
- solara/website/pages/documentation/api/hooks/use_trait_observe.py +12 -0
- solara/website/pages/documentation/api/routing/__init__.py +9 -0
- solara/website/pages/documentation/api/routing/generate_routes.py +10 -0
- solara/website/pages/documentation/api/routing/generate_routes_directory.py +10 -0
- solara/website/pages/documentation/api/routing/resolve_path.py +35 -0
- solara/website/pages/documentation/api/routing/route.py +29 -0
- solara/website/pages/documentation/api/routing/use_route.py +76 -0
- solara/website/pages/documentation/api/routing/use_router.py +16 -0
- solara/website/pages/documentation/api/utilities/__init__.py +9 -0
- solara/website/pages/documentation/api/utilities/component_vue.py +10 -0
- solara/website/pages/documentation/api/utilities/computed.py +16 -0
- solara/website/pages/documentation/api/utilities/display.py +16 -0
- solara/website/pages/documentation/api/utilities/get_kernel_id.py +16 -0
- solara/website/pages/documentation/api/utilities/get_session_id.py +16 -0
- solara/website/pages/documentation/api/utilities/memoize.py +35 -0
- solara/website/pages/documentation/api/utilities/on_kernel_start.py +44 -0
- solara/website/pages/documentation/api/utilities/reactive.py +16 -0
- solara/website/pages/documentation/api/utilities/widget.py +104 -0
- solara/website/pages/documentation/components/__init__.py +12 -0
- solara/website/pages/documentation/components/advanced/__init__.py +9 -0
- solara/website/pages/documentation/components/advanced/link.py +25 -0
- solara/website/pages/documentation/components/advanced/meta.py +17 -0
- solara/website/pages/documentation/components/advanced/style.py +43 -0
- solara/website/pages/documentation/components/common.py +9 -0
- solara/website/pages/documentation/components/data/__init__.py +9 -0
- solara/website/pages/documentation/components/data/dataframe.py +44 -0
- solara/website/pages/documentation/components/data/pivot_table.py +81 -0
- solara/website/pages/documentation/components/enterprise/__init__.py +9 -0
- solara/website/pages/documentation/components/enterprise/avatar.py +24 -0
- solara/website/pages/documentation/components/enterprise/avatar_menu.py +25 -0
- solara/website/pages/documentation/components/input/__init__.py +9 -0
- solara/website/pages/documentation/components/input/button.py +23 -0
- solara/website/pages/documentation/components/input/checkbox.py +10 -0
- solara/website/pages/documentation/components/input/file_browser.py +30 -0
- solara/website/pages/documentation/components/input/file_drop.py +76 -0
- solara/website/pages/documentation/components/input/input.py +43 -0
- solara/website/pages/documentation/components/input/select.py +22 -0
- solara/website/pages/documentation/components/input/slider.py +29 -0
- solara/website/pages/documentation/components/input/switch.py +10 -0
- solara/website/pages/documentation/components/input/togglebuttons.py +21 -0
- solara/website/pages/documentation/components/lab/__init__.py +9 -0
- solara/website/pages/documentation/components/lab/chat.py +109 -0
- solara/website/pages/documentation/components/lab/confirmation_dialog.py +55 -0
- solara/website/pages/documentation/components/lab/cookies_headers.py +48 -0
- solara/website/pages/documentation/components/lab/input_date.py +20 -0
- solara/website/pages/documentation/components/lab/input_time.py +15 -0
- solara/website/pages/documentation/components/lab/menu.py +22 -0
- solara/website/pages/documentation/components/lab/tab.py +25 -0
- solara/website/pages/documentation/components/lab/tabs.py +45 -0
- solara/website/pages/documentation/components/lab/task.py +11 -0
- solara/website/pages/documentation/components/lab/theming.py +74 -0
- solara/website/pages/documentation/components/lab/use_task.py +11 -0
- solara/website/pages/documentation/components/layout/__init__.py +9 -0
- solara/website/pages/documentation/components/layout/app_bar.py +16 -0
- solara/website/pages/documentation/components/layout/app_bar_title.py +16 -0
- solara/website/pages/documentation/components/layout/app_layout.py +24 -0
- solara/website/pages/documentation/components/layout/card.py +15 -0
- solara/website/pages/documentation/components/layout/card_actions.py +16 -0
- solara/website/pages/documentation/components/layout/column.py +30 -0
- solara/website/pages/documentation/components/layout/columns.py +27 -0
- solara/website/pages/documentation/components/layout/columns_responsive.py +66 -0
- solara/website/pages/documentation/components/layout/details.py +13 -0
- solara/website/pages/documentation/components/layout/griddraggable.py +62 -0
- solara/website/pages/documentation/components/layout/gridfixed.py +19 -0
- solara/website/pages/documentation/components/layout/hbox.py +18 -0
- solara/website/pages/documentation/components/layout/row.py +30 -0
- solara/website/pages/documentation/components/layout/sidebar.py +24 -0
- solara/website/pages/documentation/components/layout/vbox.py +19 -0
- solara/website/pages/documentation/components/output/__init__.py +9 -0
- solara/website/pages/documentation/components/output/file_download.py +11 -0
- solara/website/pages/documentation/components/output/html.py +19 -0
- solara/website/pages/documentation/components/output/image.py +11 -0
- solara/website/pages/documentation/components/output/markdown.py +57 -0
- solara/website/pages/documentation/components/output/markdown_editor.py +51 -0
- solara/website/pages/documentation/components/output/sql_code.py +83 -0
- solara/website/pages/documentation/components/output/tooltip.py +11 -0
- solara/website/pages/documentation/components/page/__init__.py +9 -0
- solara/website/pages/documentation/components/page/head.py +15 -0
- solara/website/pages/documentation/components/page/title.py +25 -0
- solara/website/pages/documentation/components/status/__init__.py +9 -0
- solara/website/pages/documentation/components/status/error.py +39 -0
- solara/website/pages/documentation/components/status/info.py +39 -0
- solara/website/pages/documentation/components/status/progress.py +10 -0
- solara/website/pages/documentation/components/status/spinner.py +11 -0
- solara/website/pages/documentation/components/status/success.py +40 -0
- solara/website/pages/documentation/components/status/warning.py +47 -0
- solara/website/pages/documentation/components/viz/__init__.py +9 -0
- solara/website/pages/documentation/components/viz/altair.py +42 -0
- solara/website/pages/documentation/components/viz/echarts.py +77 -0
- solara/website/pages/documentation/components/viz/matplotlib.py +30 -0
- solara/website/pages/documentation/components/viz/plotly.py +63 -0
- solara/website/pages/documentation/components/viz/plotly_express.py +41 -0
- solara/website/pages/documentation/examples/__init__.py +54 -0
- solara/website/pages/documentation/examples/ai/__init__.py +11 -0
- solara/website/pages/documentation/examples/ai/chatbot.py +113 -0
- solara/website/pages/documentation/examples/ai/tokenizer.py +107 -0
- solara/website/pages/documentation/examples/basics/__init__.py +10 -0
- solara/website/pages/documentation/examples/basics/sine.py +28 -0
- solara/website/pages/documentation/examples/fullscreen/__init__.py +10 -0
- solara/website/pages/documentation/examples/fullscreen/authorization.py +3 -0
- solara/website/pages/documentation/examples/fullscreen/layout_demo.py +3 -0
- solara/website/pages/documentation/examples/fullscreen/multipage.py +3 -0
- solara/website/pages/documentation/examples/fullscreen/scatter.py +3 -0
- solara/website/pages/documentation/examples/fullscreen/scrolling.py +3 -0
- solara/website/pages/documentation/examples/fullscreen/tutorial_streamlit.py +3 -0
- solara/website/pages/documentation/examples/general/__init__.py +10 -0
- solara/website/pages/documentation/examples/general/custom_storage.py +70 -0
- solara/website/pages/documentation/examples/general/deploy_model.py +115 -0
- solara/website/pages/documentation/examples/general/live_update.py +32 -0
- solara/website/pages/documentation/examples/general/login_oauth.py +81 -0
- solara/website/pages/documentation/examples/general/mycard.vue +58 -0
- solara/website/pages/documentation/examples/general/pokemon_search.py +51 -0
- solara/website/pages/documentation/examples/general/vue_component.py +50 -0
- solara/website/pages/documentation/examples/ipycanvas.py +49 -0
- solara/website/pages/documentation/examples/libraries/__init__.py +10 -0
- solara/website/pages/documentation/examples/libraries/altair.py +65 -0
- solara/website/pages/documentation/examples/libraries/bqplot.py +39 -0
- solara/website/pages/documentation/examples/libraries/ipyleaflet.py +33 -0
- solara/website/pages/documentation/examples/libraries/ipyleaflet_advanced.py +66 -0
- solara/website/pages/documentation/examples/utilities/__init__.py +10 -0
- solara/website/pages/documentation/examples/utilities/calculator.py +157 -0
- solara/website/pages/documentation/examples/utilities/countdown_timer.py +62 -0
- solara/website/pages/documentation/examples/utilities/todo.py +196 -0
- solara/website/pages/documentation/examples/visualization/__init__.py +6 -0
- solara/website/pages/documentation/examples/visualization/annotator.py +67 -0
- solara/website/pages/documentation/examples/visualization/linked_views.py +81 -0
- solara/website/pages/documentation/examples/visualization/plotly.py +44 -0
- solara/website/pages/documentation/faq/__init__.py +12 -0
- solara/website/pages/documentation/faq/content/99-faq.md +112 -0
- solara/website/pages/documentation/getting_started/__init__.py +9 -0
- solara/website/pages/documentation/getting_started/content/00-quickstart.md +107 -0
- solara/website/pages/documentation/getting_started/content/01-introduction.md +125 -0
- solara/website/pages/documentation/getting_started/content/02-installing.md +134 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/00-overview.md +14 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/10_data_science.py +13 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/20-web-app.md +89 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/30-ipywidgets.md +124 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/40-streamlit.md +146 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/50-dash.md +144 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/60-jupyter-dashboard-part1.py +65 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/SF_crime_sample.csv.gz +0 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/_data_science.ipynb +445 -0
- solara/website/pages/documentation/getting_started/content/04-tutorials/_jupyter_dashboard_1.ipynb +1021 -0
- solara/website/pages/documentation/getting_started/content/05-fundamentals/00-overview.md +11 -0
- solara/website/pages/documentation/getting_started/content/05-fundamentals/10-components.md +228 -0
- solara/website/pages/documentation/getting_started/content/05-fundamentals/50-state-management.md +278 -0
- solara/website/pages/documentation/getting_started/content/07-deploying/00-overview.md +7 -0
- solara/website/pages/documentation/getting_started/content/07-deploying/10-self-hosted.md +305 -0
- solara/website/pages/documentation/getting_started/content/07-deploying/20-cloud-hosted.md +80 -0
- solara/website/pages/documentation/getting_started/content/80-what-is-lab.md +7 -0
- solara/website/pages/documentation/getting_started/content/90-troubleshoot.md +26 -0
- solara/website/pages/docutils.py +38 -0
- solara/website/pages/home.vue +1199 -0
- solara/website/pages/our_team/__init__.py +83 -0
- solara/website/pages/pricing/__init__.py +31 -0
- solara/website/pages/roadmap/__init__.py +11 -0
- solara/website/pages/roadmap/roadmap.md +47 -0
- solara/website/pages/scale_ipywidgets.py +45 -0
- solara/website/pages/showcase/__init__.py +105 -0
- solara/website/pages/showcase/domino_code_assist.py +60 -0
- solara/website/pages/showcase/planeto_tessa.py +19 -0
- solara/website/pages/showcase/solara_dev.py +54 -0
- solara/website/pages/showcase/solarathon_2023_team_2.py +22 -0
- solara/website/pages/showcase/solarathon_2023_team_4.py +22 -0
- solara/website/pages/showcase/solarathon_2023_team_5.py +23 -0
- solara/website/pages/showcase/solarathon_2023_team_6.py +34 -0
- solara/website/pages/showcase/wanderlust.py +27 -0
- solara/website/public/beach.jpeg +0 -0
- solara/website/public/logo.svg +6 -0
- solara/website/public/social/discord.svg +1 -0
- solara/website/public/social/github.svg +1 -0
- solara/website/public/social/twitter.svg +3 -0
- solara/website/public/success.html +25 -0
- solara/website/templates/index.html.j2 +117 -0
- solara/website/utils.py +51 -0
- solara/widgets/__init__.py +1 -0
- solara/widgets/vue/gridlayout.vue +107 -0
- solara/widgets/vue/html.vue +4 -0
- solara/widgets/vue/navigator.vue +134 -0
- solara/widgets/vue/vegalite.vue +130 -0
- solara/widgets/widgets.py +74 -0
- solara_ui-1.45.0.data/data/etc/jupyter/jupyter_notebook_config.d/solara.json +7 -0
- solara_ui-1.45.0.data/data/etc/jupyter/jupyter_server_config.d/solara.json +7 -0
- solara_ui-1.45.0.dist-info/METADATA +162 -0
- solara_ui-1.45.0.dist-info/RECORD +464 -0
- solara_ui-1.45.0.dist-info/WHEEL +4 -0
- solara_ui-1.45.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Fundamentals of Solara
|
|
3
|
+
description: These articles dive deeper into the fundamental aspects of Soalra, like using components, hooks, and managing state.
|
|
4
|
+
---
|
|
5
|
+
# Fundamentals
|
|
6
|
+
|
|
7
|
+
If you want to dive deeper into Solara, this section is for you. We will cover the following topics:
|
|
8
|
+
|
|
9
|
+
* [Components](/documentation/getting_started/fundamentals/components)
|
|
10
|
+
* Hooks (soon)
|
|
11
|
+
* [State management](/documentation/getting_started/fundamentals/state-management)
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Introduction to Solara components
|
|
3
|
+
description: In Solara, components are the building blocks of your web application. They allow you to create modular, reusable, and maintainable user interface elements
|
|
4
|
+
that can be combined to create a complete and interactive application.
|
|
5
|
+
---
|
|
6
|
+
<!-- TODO: column auto -->
|
|
7
|
+
|
|
8
|
+
# Introduction to Components
|
|
9
|
+
|
|
10
|
+
In Solara, components are the building blocks of your web application. They allow you to create modular, reusable, and maintainable user interface (UI) elements that can be combined to create a complete and interactive application. Components can range from simple UI elements, such as buttons or text inputs, to more complex and custom visualizations or forms.
|
|
11
|
+
|
|
12
|
+
The primary benefits of using components in Solara include:
|
|
13
|
+
|
|
14
|
+
* Modularity: Components can be designed independently and then combined to form more complex UIs. This modular approach promotes separation of concerns, making it easier to reason about and maintain each part of your application.
|
|
15
|
+
* Reusability: Components can be reused across different parts of your application or even across multiple projects. This can save time and effort by reducing the need to rewrite similar code and can lead to more consistent UIs.
|
|
16
|
+
* Maintainability: By breaking your application into smaller, self-contained components, it becomes easier to understand, debug, and update your code. This results in more maintainable and resilient applications.
|
|
17
|
+
* Performance: When a component instance depends on a specific state, and that state changes, only the render function of the affected component instance will be re-executed. This selective re-rendering ensures that other components or instances that do not depend on the changed state remain unaffected, leading to more efficient performance.
|
|
18
|
+
|
|
19
|
+
## Types of Components
|
|
20
|
+
|
|
21
|
+
In Solara, there are two main types of components: Widget Components and Function Components.
|
|
22
|
+
|
|
23
|
+
## Widget components
|
|
24
|
+
|
|
25
|
+
Widget Components correspond to ipywidgets and are responsible for rendering visual elements in the browser, such as buttons, sliders, or performing layout tasks. These components are the foundation of your user interface and provide the essential building blocks for creating interactive applications.
|
|
26
|
+
|
|
27
|
+
Solara mainly uses the [ipyvuetify library](/documentation/advanced/understanding/ipyvuetify) for its widget components. It provides a set of high-level components that can be used to create rich, interactive user interfaces.
|
|
28
|
+
|
|
29
|
+
See the [components page](/documentation/components) for a complete list of basic UI components.
|
|
30
|
+
|
|
31
|
+
## Function Components
|
|
32
|
+
|
|
33
|
+
Function Components (Components for short), on the other hand, are responsible for combining logic, state, and other components to create more complex and dynamic applications. These components serve as a way to create reusable and modular structures that can be easily integrated into your application.
|
|
34
|
+
|
|
35
|
+
These are the components that you will be writing when building Solara applications.
|
|
36
|
+
|
|
37
|
+
By utilizing both Widget Components and Function Components, you can create flexible and powerful applications that provide a rich user experience while maintaining a clean and organized codebase.
|
|
38
|
+
|
|
39
|
+
## Creating New Components
|
|
40
|
+
|
|
41
|
+
In Solara, users can create their own custom components without any special distinction from the built-in components provided by the framework, they are all components. These user-defined components have the same capabilities and can be composed seamlessly alongside Solara's components, allowing for the creation of highly customized and reusable user interfaces.
|
|
42
|
+
|
|
43
|
+
# Defining Components
|
|
44
|
+
To create a component in Solara, you'll start by defining a Python function decorated with `@solara.component`. Inside the function, you can create the component's structure by calling Solara's built-in components or creating custom components to suit your specific needs. If a single element is created, it's taken as the component's main element. If multiple elements are created, they are automatically wrapped in a [Column component](/documentation/components/layout/column).
|
|
45
|
+
|
|
46
|
+
Here's an example of a simple Solara component that displays a button:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import solara
|
|
50
|
+
|
|
51
|
+
@solara.component
|
|
52
|
+
def MyButton():
|
|
53
|
+
solara.Button("Click me!")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
In this example, we create a component function named MyButton and apply the @solara.component decorator to it. Within the component function, a Button component from Solara is created, displaying the text "Click me!".
|
|
57
|
+
|
|
58
|
+
## Using Components
|
|
59
|
+
Once you've created your components, you can use them in your Solara app by calling the components to create elements. Elements, the lightweight representations of components, can be combined to build complex UIs. They can also be passed as arguments to other components, enabling a flexible and modular application structure.
|
|
60
|
+
|
|
61
|
+
Here's an example of using the `MyButton` component we defined earlier:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import solara
|
|
65
|
+
|
|
66
|
+
@solara.component
|
|
67
|
+
def MyApp():
|
|
68
|
+
MyButton()
|
|
69
|
+
MyButton()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
In this example, we create a `MyApp` function decorated with `@solara.component`. The function creates two MyButton elements, resulting in two buttons (or two component instances).
|
|
73
|
+
|
|
74
|
+
## Handling User Interactions
|
|
75
|
+
Components in Solara can capture user input and respond to events, such as button clicks or form submissions. To handle user interactions, you'll define callback functions and connect them to your components using Solara's event handling system.
|
|
76
|
+
|
|
77
|
+
Here's an example of a Solara component that displays a button and responds to click events:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import solara
|
|
81
|
+
|
|
82
|
+
def on_button_click(event):
|
|
83
|
+
print("Button clicked!")
|
|
84
|
+
|
|
85
|
+
@solara.component
|
|
86
|
+
def MyInteractiveButton():
|
|
87
|
+
solara.Button("Click me!", on_click=on_button_click)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
In this example, we define a function called `on_button_click` that will be executed when the button is clicked. In the `MyInteractiveButton` function, we create a Button component and set the `on_click` argument to the `on_button_click` function.
|
|
91
|
+
|
|
92
|
+
By following these steps, you can create and use components to build rich, interactive applications with Solara.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
## Component Arguments and State
|
|
96
|
+
In Solara, components can accept arguments and maintain internal state to manage their behavior and appearance. This section will explain how to use arguments and state in your Solara components and provide code examples to demonstrate their usage.
|
|
97
|
+
|
|
98
|
+
### Component Arguments
|
|
99
|
+
Arguments are the values that you pass to a component when you call it, allowing you to customize its behavior and appearance. You can define the arguments your component accepts by specifying them as parameters in the component function. This makes your components more reusable and flexible, as you can easily modify their behavior by passing different argument values.
|
|
100
|
+
|
|
101
|
+
Here's an example of a Solara component that accepts an argument:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import solara
|
|
105
|
+
|
|
106
|
+
@solara.component
|
|
107
|
+
def MyButton(text):
|
|
108
|
+
solara.Button(text)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
In this example, we define a function called MyButton that takes a single argument, text. The render function creates a Button component from Solara with the specified text.
|
|
112
|
+
|
|
113
|
+
### Using Application state in Components
|
|
114
|
+
To manage the state of a component in Solara, you can use the [`solara.reactive()`](/documentation/api/utilities/reactive) function to create reactive variables. Reactive variables are used to store values that can change over time and automatically trigger component updates when their values change. This allows you to create components that respond to changes in data and user interactions.
|
|
115
|
+
|
|
116
|
+
Here's an example that demonstrates the use of reactive variables in Solara components:
|
|
117
|
+
```solara
|
|
118
|
+
import solara
|
|
119
|
+
|
|
120
|
+
counter = solara.reactive(0)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def increment():
|
|
124
|
+
counter.value += 1
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@solara.component
|
|
128
|
+
def CounterDisplay():
|
|
129
|
+
solara.Info(f"Counter: {counter.value}")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@solara.component
|
|
133
|
+
def IncrementButton():
|
|
134
|
+
solara.Button("Increment", on_click=increment)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@solara.component
|
|
138
|
+
def Page():
|
|
139
|
+
IncrementButton()
|
|
140
|
+
CounterDisplay()
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
In this example, we create a reactive variable counter with an initial value of 0. We define two components: `CounterDisplay` and `IncrementButton`. `CounterDisplay` renders the current value of counter, while `IncrementButton` increments the value of counter when clicked. Whenever the counter value changes, `CounterDisplay` automatically updates to display the new value.
|
|
144
|
+
|
|
145
|
+
By using arguments and state in your Solara components, you can create more dynamic and interactive applications that respond to user input and changes in data.
|
|
146
|
+
|
|
147
|
+
### Internal State in Components
|
|
148
|
+
|
|
149
|
+
In addition to using reactive variables for global or application-wide state, you can also manage internal or component-specific state using the [`use_reactive`](/documentation/api/hooks/use_reactive) hook in Solara. The `use_reactive` hook allows you to define reactive variables which are local to a component, and automatically trigger updates when their values change.
|
|
150
|
+
|
|
151
|
+
To use the `use_reactive` hook, call the solara.use_reactive() function inside your component function. This function takes an initial value as an argument and returns a the same reactive variable on each render.
|
|
152
|
+
|
|
153
|
+
Here's an example that demonstrates the use of the use_reactive hook to manage internal state in a Solara component:
|
|
154
|
+
|
|
155
|
+
```solara
|
|
156
|
+
import solara
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@solara.component
|
|
160
|
+
def Counter():
|
|
161
|
+
count = solara.use_reactive(0)
|
|
162
|
+
|
|
163
|
+
def increment():
|
|
164
|
+
count.value += 1
|
|
165
|
+
|
|
166
|
+
solara.Button("Increment", on_click=increment)
|
|
167
|
+
solara.Info(f"Counter: {count.value}")
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@solara.component
|
|
171
|
+
def Page():
|
|
172
|
+
Counter()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
In this example, we define a Counter component that uses the `use_reactive` hook to manage its internal state. We create a reactive variable called `count` with an initial value of 0 and a function `increment` to update the state. The increment function increments the value of count when the button is clicked. Whenever the count value changes, the component automatically updates to display the new value.
|
|
176
|
+
|
|
177
|
+
By using the `use_reactive` hook, you can manage the internal state of your components and create more dynamic and interactive applications that respond to user input and changes in data.
|
|
178
|
+
|
|
179
|
+
## Lazy Rendering in Solara Components
|
|
180
|
+
|
|
181
|
+
In Solara, understanding the relationship between components, elements, and instances is essential to grasp the rendering process. Components serve as a blueprint or template for defining the structure and behavior of a part of the user interface. Elements are lightweight virtual representations of components, created when the components are invoked. Instances, on the other hand, represent the function body of the component and its state.
|
|
182
|
+
|
|
183
|
+
Solara employs a "lazy rendering" approach, where the rendering of a component's children is deferred until it is necessary. When a component is invoked, an element is created immediately, representing that particular instance of the component. However, the actual rendering of the component's children is postponed until the component is rendered within the virtual tree, either as a child of another component or as the root component. This allows Solara to optimize the rendering process and update only the necessary components when the application state or component arguments change.
|
|
184
|
+
|
|
185
|
+
Lazy rendering in Solara ensures that the render function is executed only when necessary, improving the application's performance. To illustrate this concept, let's consider the following example:
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
```solara
|
|
189
|
+
import solara
|
|
190
|
+
|
|
191
|
+
counter = solara.reactive(0)
|
|
192
|
+
|
|
193
|
+
@solara.component
|
|
194
|
+
def CounterDisplay():
|
|
195
|
+
solara.Info(f"Counter: {counter.value}")
|
|
196
|
+
|
|
197
|
+
@solara.component
|
|
198
|
+
def IncrementButton():
|
|
199
|
+
def increment():
|
|
200
|
+
counter.value += 1
|
|
201
|
+
|
|
202
|
+
solara.Button("Increment", on_click=increment)
|
|
203
|
+
|
|
204
|
+
@solara.component
|
|
205
|
+
def RandomText():
|
|
206
|
+
import random
|
|
207
|
+
solara.Info(f"Random number: {random.random()}")
|
|
208
|
+
|
|
209
|
+
@solara.component
|
|
210
|
+
def Page():
|
|
211
|
+
IncrementButton()
|
|
212
|
+
CounterDisplay()
|
|
213
|
+
RandomText()
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
In this example, we define several components: `IncrementButton`, `CounterDisplay`, and `RandomText`. The `IncrementButton` component increments the value of the counter reactive variable when clicked. The `CounterDisplay` component displays the current value of the counter. The `RandomText` component displays a random number but does not depend on any state or reactive variables.
|
|
217
|
+
|
|
218
|
+
When the user clicks the `IncrementButton`, the counter reactive variable is updated, and the `CounterDisplay` component re-renders to show the new value. The RandomText component does not re-render in this scenario because it does not depend on any state or reactive variables.
|
|
219
|
+
|
|
220
|
+
This example demonstrates Solara's lazy rendering, where only the relevant components are instantiated and rendered based on changes in their arguments or internal state. This ensures that the render function is executed only when necessary, improving the application's performance.
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
## Conclusions
|
|
224
|
+
In conclusion, understanding components, their arguments, and how to manage their internal state is crucial for building Solara applications. To create more advanced components, you need to have a deeper understanding of hooks, such as the `use_reactive` hook we have already discussed.
|
|
225
|
+
|
|
226
|
+
In the next fundamentals article, we will explore more hooks available in Solara, which will enable you to build more sophisticated components that cater to a wide range of use cases. By learning about hooks, you can create powerful components that can manage state, interact with other components, and respond to user input.
|
|
227
|
+
|
|
228
|
+
To summarize, components are the building blocks of Solara applications, and they can accept arguments to customize their behavior and appearance. Managing state in components can be done either through local (component) state or application-wide state, each with its advantages and disadvantages. By striking a balance between reusable components and application-specific code, you can create scalable and maintainable applications in Solara. With a solid understanding of components and their state management, you are well on your way to creating powerful and interactive web applications with Solara.
|
solara/website/pages/documentation/getting_started/content/05-fundamentals/50-state-management.md
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Introduction to state management in Solara
|
|
3
|
+
description: State management is a crucial aspect of building data-focused web applications with Solara. By effectively managing state, you can create interactive
|
|
4
|
+
and responsive applications that react to changes in data and user input.
|
|
5
|
+
---
|
|
6
|
+
# Introduction
|
|
7
|
+
|
|
8
|
+
State management is a crucial aspect of building data-focused web applications with Solara. By effectively managing state, you can create interactive and responsive applications that react to changes in data and user input. In Solara, there are two primary ways to define state: global application state using [`solara.reactive`](/documentation/api/utilities/reactive) and local component state using [`solara.use_state`](/documentation/api/hooks/use_state) or [`solara.use_reactive`](/documentation/api/hooks/use_reactive). This article will discuss these two approaches and provide examples of how to use them in your Solara applications.
|
|
9
|
+
|
|
10
|
+
## Two main ways of defining state in Solara
|
|
11
|
+
|
|
12
|
+
### Global application state using solara.reactive
|
|
13
|
+
|
|
14
|
+
Using [`solara.reactive`](/documentation/api/utilities/reactive) allows you to create global state variables that can be accessed and modified from any component within your application. This approach is useful when you need to manage state that is shared across multiple components or when you want to maintain consistency throughout your application.
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
|
|
18
|
+
```solara
|
|
19
|
+
import solara
|
|
20
|
+
|
|
21
|
+
color = solara.reactive("red")
|
|
22
|
+
|
|
23
|
+
@solara.component
|
|
24
|
+
def SomeAppSpecificComponent():
|
|
25
|
+
solara.Select(label="Color", values=["red", "green", "blue", "orange"], value=color)
|
|
26
|
+
solara.Markdown("### Solara is awesome", style={"color": color.value})
|
|
27
|
+
|
|
28
|
+
@solara.component
|
|
29
|
+
def Page():
|
|
30
|
+
SomeAppSpecificComponent()
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
In this case, the `SomeAppSpecificComponent` is not reusable in the sense that a second component has a different state. The `color` variable is global and shared across all components. This component is meant to be used only once, and mainly helps to organize the code.
|
|
35
|
+
|
|
36
|
+
You may have heard that globals are considered a bad practice. As with many things, it depends on the context. A possible downside of using a global is that it does not
|
|
37
|
+
allow you to create multiple instances of the same component with different states. But if the state reflects application state, there is by definition only one instance
|
|
38
|
+
of it needed.
|
|
39
|
+
|
|
40
|
+
### Local component state using solara.use_reactive
|
|
41
|
+
|
|
42
|
+
If you do need state that is specific to a component, you should use [`solara.use_reactive`](/documentation/api/hooks/use_reactive) hook. This hook allow you to create local state variables that are scoped to a specific component. This approach is useful when you want to encapsulate state within a component, making it self-contained and modular. Local state management is suitable for situations where state changes only affect the component and do not need to be shared across the application.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
```solara hl_lines="6 8"
|
|
46
|
+
import solara
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@solara.component
|
|
50
|
+
def ReusableComponent():
|
|
51
|
+
color = solara.use_reactive("red") # local state (instead of top level solara.reactive)
|
|
52
|
+
solara.Select(label="Color",values=["red", "green", "blue", "orange"],
|
|
53
|
+
value=color)
|
|
54
|
+
solara.Markdown("### Solara is awesome", style={"color": color.value})
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@solara.component
|
|
58
|
+
def Page():
|
|
59
|
+
# this component is used twice, but each instance has its own state
|
|
60
|
+
ReusableComponent()
|
|
61
|
+
ReusableComponent()
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Local component state using solara.use_state (not recommended)
|
|
66
|
+
|
|
67
|
+
[`solara.use_state`](/documentation/api/hooks/use_state) is a hook that might be a bit more familiar to React developers. It also allows you to create local state variables that are scoped to a specific component, however, instead of using reactive variables, it uses a tuple of a value and a setter function.
|
|
68
|
+
|
|
69
|
+
We generally recommend using `use_reactive` over `use_state` as it is more easy to refactor between global application state and local component state by switching between `use_reactive` and `reactive`. There is no equivalent for `use_state` at the global level.
|
|
70
|
+
|
|
71
|
+
If we take the previous example and replace `use_reactive` by `use_state`, we get:
|
|
72
|
+
|
|
73
|
+
Example:
|
|
74
|
+
```solara hl_lines="6 9"
|
|
75
|
+
import solara
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@solara.component
|
|
79
|
+
def ReusableComponent():
|
|
80
|
+
# color = solara.use_reactive("red") # instead of use_reactive (not recommended)
|
|
81
|
+
color, set_color = solara.use_state("red") # local state
|
|
82
|
+
solara.Select(label="Color",values=["red", "green", "blue", "orange"],
|
|
83
|
+
value=color, on_value=set_color)
|
|
84
|
+
solara.Markdown("### Solara is awesome", style={"color": color})
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@solara.component
|
|
88
|
+
def Page():
|
|
89
|
+
# this component is used twice, but each instance has its own state
|
|
90
|
+
ReusableComponent()
|
|
91
|
+
ReusableComponent()
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Mutation pittfalls
|
|
96
|
+
|
|
97
|
+
In Python, strings, numbers, and tuples are immutable. This means that you cannot change the value of a string, number, or tuple in place.
|
|
98
|
+
Instead, you need to create a new object and assign that to a variable.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
a = 1
|
|
102
|
+
b = a
|
|
103
|
+
# a.value = 2 # ERROR: numbers are immutable
|
|
104
|
+
a = 2 # instead, re-assign a new value, the number 1 will not change
|
|
105
|
+
assert b == 1 # b is still 1
|
|
106
|
+
```
|
|
107
|
+
However, many objects in Python are mutable, including lists and dictionaries or potentially user defined classes. This means that you can change the value of a list, dictionary, or user defined class in place without creating a new object.
|
|
108
|
+
```python
|
|
109
|
+
a = [1, 2, 3]
|
|
110
|
+
b = a # b points to the same list as a
|
|
111
|
+
a.append(4) # a is now [1, 2, 3, 4]
|
|
112
|
+
assert b == [1, 2, 3, 4] # b is also [1, 2, 3, 4]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Not mutating lists
|
|
116
|
+
|
|
117
|
+
However, mutations in Python are not observable. **This means that if you change the value of a list, dictionary, or user defined class, Solara does not know that the value has changed and does not know it needs to re-render a component that uses that value.**
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
import solara
|
|
121
|
+
|
|
122
|
+
reactive_list = solara.reactive([1, 2, 3])
|
|
123
|
+
# The next line will not trigger a re-render of a component
|
|
124
|
+
reactive_list.value.append(4) # ERROR: mutating a list is not observable in Python
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Although Solara could potentially track mutations of lists and dictionaries, that would be difficult to do for user defined classes, since we would need to know which methods mutate the object and which do not. Therefore, we have chosen not to include
|
|
128
|
+
any magic tracking of mutations in Solara, and instead require you to re-assign a new value to a reactive variable if you want to trigger a re-render.
|
|
129
|
+
|
|
130
|
+
```python hl_lines="5"
|
|
131
|
+
import solara
|
|
132
|
+
|
|
133
|
+
reactive_list = solara.reactive([1, 2, 3])
|
|
134
|
+
# Instead, re-assign a new value
|
|
135
|
+
reactive_list.value = [*reactive_list.value, 4] # GOOD: re-assign a new list
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Not mutating dictionaries
|
|
139
|
+
|
|
140
|
+
A similar pattern applies to dictionaries.
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
import solara
|
|
144
|
+
|
|
145
|
+
reactive_dict = solara.reactive({"a": 1, "b": 2})
|
|
146
|
+
reactive_dict.value = {**reactive_dict.value, "c": 3} # GOOD: re-assign a new dictionary
|
|
147
|
+
# deleting a key
|
|
148
|
+
reactive_dict.value = {k: v for k, v in reactive_dict.value.items() if k != "a"} # GOOD: re-assign a new dictionary
|
|
149
|
+
# deleting a key (method 2)
|
|
150
|
+
dict_copy = reactive_dict.value.copy()
|
|
151
|
+
del dict_copy["b"]
|
|
152
|
+
reactive_dict.value = dict_copy # GOOD: re-assign a new dictionary
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Not mutating user defined classes
|
|
156
|
+
|
|
157
|
+
Or user defined classes, like a Pandas DataFrame.
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
import solara
|
|
161
|
+
import pandas as pd
|
|
162
|
+
|
|
163
|
+
reactive_df = solara.reactive(pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}))
|
|
164
|
+
# reactive_df.value.append({"a": 4, "b": 7}) # BAD: mutating a DataFrame is not observable in Python
|
|
165
|
+
df_copy = reactive_df.value.copy(deep=True) # for Pandas 3, deep=True is not necessary
|
|
166
|
+
df_copy = df_copy.append({"a": 4, "b": 7}, ignore_index=True)
|
|
167
|
+
reactive_df.value = df_copy # GOOD: re-assign a new DataFrame
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
## Creating a store
|
|
172
|
+
|
|
173
|
+
Using reactive variables is a powerful way to manage state in your Solara applications. However, as your application grows, you may find that you need a more structured way to manage your state.
|
|
174
|
+
|
|
175
|
+
In larger applications, you may want to create a store to manage your application's state. A store is a regular Python class where all attributes are reactive variables.
|
|
176
|
+
|
|
177
|
+
In your Python class you are free to expose the reactive variables as attributes, or you can create properties to make certain attributes read-only or to add additional logic when setting an attribute.
|
|
178
|
+
|
|
179
|
+
A complete TODO application demonstrates this below.
|
|
180
|
+
|
|
181
|
+
```solara
|
|
182
|
+
import uuid
|
|
183
|
+
from typing import Callable
|
|
184
|
+
|
|
185
|
+
import solara
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# this todo item is only a collection of reactive values
|
|
189
|
+
class TodoItem:
|
|
190
|
+
def __init__(self, text: str, done: bool = False):
|
|
191
|
+
self.text = solara.reactive(text)
|
|
192
|
+
self.done = solara.reactive(done)
|
|
193
|
+
self._uuid = solara.reactive(str(uuid.uuid4()))
|
|
194
|
+
self._dirty = solara.reactive(True)
|
|
195
|
+
|
|
196
|
+
def __str__(self) -> str:
|
|
197
|
+
return f"{self.text.value} ({'done' if self.done else 'not done'})"
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# However, this class really adds some logic to the todo items
|
|
201
|
+
class TodoStore:
|
|
202
|
+
def __init__(self, items: list[TodoItem]):
|
|
203
|
+
# we keep the items as a protected attribute
|
|
204
|
+
self._items = solara.reactive(items)
|
|
205
|
+
self.add_item_text = solara.reactive("")
|
|
206
|
+
|
|
207
|
+
@property
|
|
208
|
+
def items(self):
|
|
209
|
+
# and make the items read only for a property
|
|
210
|
+
return self._items.value
|
|
211
|
+
|
|
212
|
+
def add_item(self, item):
|
|
213
|
+
self._items.value = [*self._items.value, item]
|
|
214
|
+
# reset the new text after adding a new item
|
|
215
|
+
self.add_item_text.value = ""
|
|
216
|
+
|
|
217
|
+
def add(self):
|
|
218
|
+
self.add_item(TodoItem(text=self.add_item_text.value))
|
|
219
|
+
|
|
220
|
+
def remove(self, item: TodoItem):
|
|
221
|
+
self._items.value = [k for k in self.items if k._uuid.value != item._uuid.value]
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def done_count(self):
|
|
225
|
+
return len([k for k in self.items if k.done.value])
|
|
226
|
+
|
|
227
|
+
@property
|
|
228
|
+
def done_percentage(self):
|
|
229
|
+
if len(self.items) == 0:
|
|
230
|
+
return 0
|
|
231
|
+
else:
|
|
232
|
+
return self.done_count / len(self.items) * 100
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@solara.component
|
|
236
|
+
def TodoItemCard(item: TodoItem, on_remove: Callable[[TodoItem], None]):
|
|
237
|
+
with solara.Card():
|
|
238
|
+
solara.InputText("", value=item.text)
|
|
239
|
+
solara.Switch(label="Done", value=item.done)
|
|
240
|
+
solara.Button("Remove", on_click=lambda: on_remove(item))
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
# The TodoApp component is reusable, so in the future
|
|
244
|
+
# we could have multiple TodoApp components if needed
|
|
245
|
+
# (e.g. multiple lists of todos)
|
|
246
|
+
|
|
247
|
+
default_store = TodoStore(
|
|
248
|
+
[
|
|
249
|
+
TodoItem(text="Write a blog post", done=False),
|
|
250
|
+
TodoItem(text="Take out the trash", done=True),
|
|
251
|
+
TodoItem(text="Do the laundry", done=False),
|
|
252
|
+
]
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
@solara.component
|
|
257
|
+
def TodoApp(store: TodoStore = default_store):
|
|
258
|
+
for item in store.items:
|
|
259
|
+
TodoItemCard(item, on_remove=store.remove)
|
|
260
|
+
|
|
261
|
+
with solara.Card("New item"):
|
|
262
|
+
solara.InputText(label="Text", value=store.add_item_text)
|
|
263
|
+
solara.Button("Add new", on_click=store.add)
|
|
264
|
+
solara.ProgressLinear(value=store.done_percentage)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
@solara.component
|
|
268
|
+
def Page():
|
|
269
|
+
TodoApp()
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
## Conclusion
|
|
276
|
+
Understanding the advantages and disadvantages of reusable components and application-specific code can help you strike the right balance between modularity and simplicity when building your Solara applications.
|
|
277
|
+
|
|
278
|
+
By understanding the trade-offs between local and application state, as well as reusable components and application-specific code, you can make better decisions when designing and building your Solara applications. Both approaches have their benefits and drawbacks, but choosing the right method for your specific use case will help you create more efficient, maintainable, and scalable applications.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Overview of how to deploy your Solara application or dashboard
|
|
3
|
+
description: Solara apps can be easily either self hosted, or hosted on a variety of cloud platforms.
|
|
4
|
+
---
|
|
5
|
+
# Deploying a solara app
|
|
6
|
+
|
|
7
|
+
A Solara app can be [self hosted](/documentation/getting_started/deploying/self-hosted) or [cloud hosted](/documentation/getting_started/deploying/cloud-hosted).
|