Fix import problem. The app didn't run from a notebooks/<>.ipynb. This however may not be needed any longer. Is it good practice to run dashboards from a jupyter notebook?

This commit is contained in:
2025-03-18 07:14:44 +01:00
parent 395b734cd6
commit f3010bff47
2 changed files with 27 additions and 9 deletions

View File

@ -1,17 +1,31 @@
import sys, os
try:
thisFilePath = os.path.abspath(__file__)
print(thisFilePath)
except NameError:
print("[Notice] The __file__ attribute is unavailable in this environment (e.g., Jupyter or IDLE).")
print("When using a terminal, make sure the working directory is set to the script's location to prevent path issues (for the DIMA submodule)")
#print("Otherwise, path to submodule DIMA may not be resolved properly.")
thisFilePath = os.getcwd() # Use current directory or specify a default
projectPath = os.path.normpath(os.path.join(thisFilePath, "..","..", ".."))
from dash import Dash, html, dcc, callback, Output, Input, State, dash_table
import dash_bootstrap_components as dbc
import yaml
from app import data_flagging_utils
with open('app/flags/ebas_dict.yaml') as stream:
with open(os.path.join(projectPath,'app/flags/ebas_dict.yaml')) as stream:
try:
flags_dict = yaml.safe_load(stream)["flags"]
except yaml.YAMLError as exc:
flags_dict = {}
print(exc)
import data_flagging_utils
flagging_dashboard = dbc.Row([
html.H3("Create flags"),

View File

@ -30,7 +30,7 @@ import io
#sys.path.append(os.path.join(root_dir,'dima'))
import data_flagging_utils as data_flagging_utils
import app.data_flagging_utils as data_flagging_utils
from dash import Dash, html, dcc, callback, Output, Input, State, dash_table
import plotly.graph_objs as go
@ -50,12 +50,12 @@ import webbrowser
from time import sleep
from components.instrument_dashboard import instrument_dashboard
from components.flagging_dashboard import flagging_dashboard
from components.upload_component import upload_component
from app.components.instrument_dashboard import instrument_dashboard
from app.components.flagging_dashboard import flagging_dashboard
from app.components.upload_component import upload_component
import yaml
with open('app/flags/ebas_dict.yaml') as stream:
with open(os.path.join(projectPath,'app/flags/ebas_dict.yaml')) as stream:
try:
flags_dict = yaml.safe_load(stream)["flags"]
except yaml.YAMLError as exc:
@ -776,9 +776,13 @@ def open_browser():
if not os.getenv("DOCKER_CONTAINER"):
webbrowser.open_new("http://127.0.0.1:8050/")
if __name__ == '__main__':
def main():
# Start the browser-opening function in a separate thread
threading.Thread(target=open_browser).start()
# Run the Dash app server on 0.0.0.0 to allow external access
app.run_server(host="0.0.0.0", port=8050, debug=True, use_reloader=False)
app.run_server(host="0.0.0.0", port=8050, debug=True, use_reloader=False)
if __name__ == '__main__':
main()