Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
singlestore-labs
GitHub Repository: singlestore-labs/singlestoredb-python
Path: blob/main/singlestoredb/apps/_dashboards.py
469 views
1
import typing
2
3
from ._config import AppConfig
4
from ._process import kill_process_by_port
5
from ._stdout_supress import StdoutSuppressor
6
from singlestoredb.apps._connection_info import ConnectionInfo
7
8
if typing.TYPE_CHECKING:
9
from dash import Dash
10
11
12
async def run_dashboard_app(
13
app: 'Dash',
14
debug: bool = False,
15
kill_existing_app_server: bool = True,
16
) -> ConnectionInfo:
17
try:
18
from dash import Dash
19
except ImportError:
20
raise ImportError('package dash is required to run dashboards')
21
22
if not isinstance(app, Dash):
23
raise TypeError('app is not an instance of Dash App')
24
25
app_config = AppConfig.from_env()
26
27
if kill_existing_app_server:
28
kill_process_by_port(app_config.listen_port)
29
30
if app.config.requests_pathname_prefix is None or \
31
app.config.requests_pathname_prefix != app_config.base_path:
32
raise RuntimeError('''
33
requests_pathname_prefix of the Dash App is invalid. Please set
34
requests_pathname_prefix=os.environ['SINGLESTOREDB_APP_BASE_PATH']
35
while initializing the Dash App and retry''')
36
37
with StdoutSuppressor():
38
app.run(
39
host='0.0.0.0',
40
debug=debug,
41
port=str(app_config.listen_port),
42
jupyter_mode='external',
43
)
44
45
if app_config.running_interactively:
46
print(f'Dash app available at {app_config.base_url}?authToken={app_config.token}')
47
return ConnectionInfo(app_config.base_url, app_config.token)
48
49