Path: blob/main/singlestoredb/apps/_dashboards.py
469 views
import typing12from ._config import AppConfig3from ._process import kill_process_by_port4from ._stdout_supress import StdoutSuppressor5from singlestoredb.apps._connection_info import ConnectionInfo67if typing.TYPE_CHECKING:8from dash import Dash91011async def run_dashboard_app(12app: 'Dash',13debug: bool = False,14kill_existing_app_server: bool = True,15) -> ConnectionInfo:16try:17from dash import Dash18except ImportError:19raise ImportError('package dash is required to run dashboards')2021if not isinstance(app, Dash):22raise TypeError('app is not an instance of Dash App')2324app_config = AppConfig.from_env()2526if kill_existing_app_server:27kill_process_by_port(app_config.listen_port)2829if app.config.requests_pathname_prefix is None or \30app.config.requests_pathname_prefix != app_config.base_path:31raise RuntimeError('''32requests_pathname_prefix of the Dash App is invalid. Please set33requests_pathname_prefix=os.environ['SINGLESTOREDB_APP_BASE_PATH']34while initializing the Dash App and retry''')3536with StdoutSuppressor():37app.run(38host='0.0.0.0',39debug=debug,40port=str(app_config.listen_port),41jupyter_mode='external',42)4344if app_config.running_interactively:45print(f'Dash app available at {app_config.base_url}?authToken={app_config.token}')46return ConnectionInfo(app_config.base_url, app_config.token)474849