restructured app
This commit is contained in:
+58
-21
@@ -1,28 +1,65 @@
|
|||||||
from dash import Dash, html, Input, Output, State, page_container, page_registry
|
from dash import Dash, Input, Output
|
||||||
import dash_bootstrap_components as dbc
|
import dash_bootstrap_components as dbc
|
||||||
import dash_mantine_components as dmc
|
import logging
|
||||||
|
|
||||||
from .header import generate_header
|
|
||||||
from .body import generate_body
|
|
||||||
|
|
||||||
|
from .layout import app_layout
|
||||||
|
from src.database import (
|
||||||
|
connect,
|
||||||
|
get_visual_communication,
|
||||||
|
NoDocumentFoundException
|
||||||
|
)
|
||||||
|
|
||||||
|
# setup app
|
||||||
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
||||||
|
app.title = "visual critical discourse analysis".title()
|
||||||
|
app.layout = app_layout
|
||||||
server = app.server
|
server = app.server
|
||||||
|
|
||||||
app.layout = dmc.MantineProvider(
|
# connect to database
|
||||||
theme={
|
collection, db, client = connect()
|
||||||
'fontFamily': '"Inter", sans-serif',
|
|
||||||
"components": {
|
# define callbacks
|
||||||
"NavLink":{'styles':{'label':{'color':'#c2c7d0'}}}
|
@app.callback(
|
||||||
},
|
Output("alert-element", "is_open"),
|
||||||
},
|
Output("alert-element", "children"),
|
||||||
children=[
|
Input("alert-message", "data")
|
||||||
dmc.Container(
|
|
||||||
[
|
|
||||||
generate_header(),
|
|
||||||
generate_body(),
|
|
||||||
], fluid=True
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
def show_alert(
|
||||||
|
msg: str | None
|
||||||
|
):
|
||||||
|
if msg is None:
|
||||||
|
return False, ""
|
||||||
|
return True, msg
|
||||||
|
|
||||||
|
@app.callback(
|
||||||
|
Output("alert-message", "data"),
|
||||||
|
Output("visual-communication-name", "data"),
|
||||||
|
Output("image-container", "src"),
|
||||||
|
Input("next-button", "n_clicks"),
|
||||||
|
prevent_initial_call=True
|
||||||
|
)
|
||||||
|
def load_unannotated_visual_communication_data(
|
||||||
|
n_clicks: int
|
||||||
|
):
|
||||||
|
global collection
|
||||||
|
try:
|
||||||
|
vis_com = get_visual_communication(
|
||||||
|
collection=collection,
|
||||||
|
with_annotation=False
|
||||||
|
)
|
||||||
|
except NoDocumentFoundException:
|
||||||
|
return (
|
||||||
|
"Did not find any unannotated data in database",
|
||||||
|
None,
|
||||||
|
""
|
||||||
|
)
|
||||||
|
# prepare return values
|
||||||
|
alert_message = None
|
||||||
|
vis_com_name = vis_com.name
|
||||||
|
img_src = f"data:image/png;base64, {vis_com.webencoded_image()}"
|
||||||
|
logging.info("updated visual communication")
|
||||||
|
return (
|
||||||
|
alert_message,
|
||||||
|
vis_com_name,
|
||||||
|
img_src
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user