Skip to content

Instantly share code, notes, and snippets.

@AdamSpannbauer
Last active June 27, 2022 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamSpannbauer/67d76efa0c69026599c899f0d4655893 to your computer and use it in GitHub Desktop.
Save AdamSpannbauer/67d76efa0c69026599c899f0d4655893 to your computer and use it in GitHub Desktop.
Test using PyWebView to run a Plotly Dash app as a native web app
import webview
from dash import Dash, html
def run_native_dash_app(dash_app: Dash, window_title: str = None) -> None:
"""Run dash app as native web app
Use PyWebView to run a dash app as a native web app
* install with `pip install pywebview`
* project home page: https://pywebview.flowrl.com/
* github: https://github.com/r0x0r/pywebview
* Actively developed as of 2022-04-27 (checked on 2022-06-27)
:param dash_app: a dash app with server and title attributes
:param window_title: title for app window; use None if `dash_app.title` should be used
:return: None
>>> app = Dash('Native Dash App Demo')
>>> app.layout = html.Div(['App Layout'])
>>> run_native_dash_app(app)
"""
if window_title is None:
window_title = dash_app.title
webview.create_window(window_title, dash_app.server)
webview.start()
if __name__ == "__main__":
# Demo app to input text and output text in all caps
from dash import dcc, Input, Output
app = Dash("Native Dash App Demo")
app.layout = html.Div(
[
html.Div(["input text: ", dcc.Input(id="my-input", type="text")]),
html.Div(id="my-output"),
]
)
@app.callback(
Output(component_id="my-output", component_property="children"),
Input(component_id="my-input", component_property="value"),
)
def update_output_div(input_value):
return f"{input_value.upper()}"
run_native_dash_app(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment