Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visible Does not Work when the output is set using set_props #56

Open
sssaha opened this issue Dec 16, 2024 · 2 comments
Open

Visible Does not Work when the output is set using set_props #56

sssaha opened this issue Dec 16, 2024 · 2 comments

Comments

@sssaha
Copy link

sssaha commented Dec 16, 2024

This might be an advanced problem - but this was the scenario of how my code is setup.

import dash_mantine_components as dmc
import dash
from dash import Dash, html, dcc, callback, Input, State, Output
from dash_pydantic_form import ModelForm, Sections, FormSection, fields
from pydantic import BaseModel, Field, ValidationError, root_validator, model_validator, validator, field_validator, SkipValidation
import dash_bootstrap_components as dbc
from typing import Literal, Optional
from datetime import date, datetime

dash._dash_renderer._set_react_version('18.2.0')
app = Dash(__name__, url_base_pathname="/", external_stylesheets=dmc.styles.ALL + [dbc.themes.BOOTSTRAP], )


class MeasurementDataMapper(BaseModel):
    time_data: str = Field(title="Timestamp Column", min_length=1, json_schema_extra={"repr_type": "Select", "repr_kwargs": {"n_cols": 2}, "comboboxProps": dict(zIndex=8000), })
    time_type: Literal['Relative', 'Absolute'] = Field(title='Time Type', default='Absolute',
                                                       json_schema_extra={"repr_type": "Select", "repr_kwargs": {"n_cols": 2, "comboboxProps": dict(zIndex=8000), 'allowDeselect': False}})
    time_format: Literal["HH:mm:ss", "ss", 'YYYY-MM-DD HH:mm:ss', 'YYYY/MM/DD HH:mm:ss'] = Field(title="Timestamp Format", default='HH:mm:SS', json_schema_extra={
        "repr_kwargs": {"n_cols": 4, 'allowDeselect': False, "comboboxProps": dict(zIndex=8000), "visible": ("time_type", "==", "Absolute")}})
    trigger_date_time: Optional[date] = Field(title='Trigger Date and Time', default=datetime.now(),
                                              json_schema_extra={"repr_kwargs": {"n_cols": 2, "popoverProps": dict(zIndex=8000), 'visible': ("time_type", "!=", "Absolute"),
                                                                                 'valueFormat': "YYYY-MM-DD HH:mm:ss.SSS"}})

    time_interval: Literal['Seconds', 'Milliseconds'] = Field(title='Time Interval', default='Seconds',
                                                              json_schema_extra={"repr_type": "Select", "repr_kwargs": {"n_cols": 2, 'visible': ("time_type", "!=", "Absolute"),
                                                                                                                        "comboboxProps": dict(zIndex=8000)}})
    phase_a_voltage_scaling: float = Field(title="Scaling", default=1, ge=0.0001,
                                           json_schema_extra={"repr_type": "NumberInput", "repr_kwargs": {"n_cols": 1, 'allowNegative': False, 'decimalScale': 4, 'step': 0.0001,
                                                                                                          'clampBehavior': "strict", }})


app.layout = dmc.MantineProvider(
    children=[dmc.Button('Submit', id='submit'),
              dmc.Modal(children=dmc.Grid(children=[
                  dmc.GridCol(span=12, children=[], id='measurement_data_mapper'),
                  dmc.GridCol(span=3, offset=9, children=dmc.Button('Save Mapper & Process File', color='green', fullWidth=True, id='submit_file_mapper_button')),
              ]), opened=True)
              ]
)


@callback(Output('submit', 'disabled'), Input('submit', 'n_clicks'))
def update(n):
    dash.set_props('measurement_data_mapper', {'children': ModelForm(MeasurementDataMapper, "measurement", "auto", submit_on_enter=True,
                                                                     fields_repr={'time_data': fields.Select(data=['Time_x', 'Time_y'])})})
    return dash.no_update





if __name__ == "__main__":
    app.run_server(debug=True)

The visible argument does not work if the Modelform was set using the dash.set_props function

@RenaudLN
Copy link
Owner

Hey @sssaha I've tried your example and indeed it doesn't seem to update or even trigger the clientside callback that is supposed to update the visibility. Not sure what's happening here but it looks like it's an issue with Dash treating the outputs of set_props differently from regular outputs.

@sssaha
Copy link
Author

sssaha commented Dec 16, 2024

Maybe we need to create another example of some sort and post it in dash forum. If it is indeed a limitation of set_props - that should be part of the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants