RenaudLN / dash-pydantic-form

MIT License
31 stars 6 forks source link

Issue with: @mantine/core: MantineProvider was not found in component tree, make sure you have it in your app #4

Closed maxschulz-COL closed 6 months ago

maxschulz-COL commented 6 months ago

Hey! As said on the plotly forums, really cool stuff! Love it!

Was just trying it out, and for me your basic example does not work due to some error with mantine:

@mantine/core: MantineProvider was not found in component tree, make sure you have it in your app

Have you ever encountered that?

I am using the following toy code:

from datetime import date
from typing import Literal
from pydantic import BaseModel, Field
from dash import Dash, html, dcc, callback, Output, Input
import plotly.express as px
import pandas as pd

from dash_pydantic_form import ModelForm

class Employee(BaseModel):
    first_name: str = Field(title="First name")
    last_name: str = Field(title="Last name")
    office: Literal["au", "uk", "us", "fr"] = Field(title="Office")
    joined: date = Field(title="Employment date")

# somewhere in your layout:
form = ModelForm(
    Employee,
    aio_id="employees",
    form_id="new_employee",
)

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv')

app = Dash()

app.layout = [
    html.H1(children='Title of Dash App', style={'textAlign':'center'}),
    dcc.Dropdown(df.country.unique(), 'Canada', id='dropdown-selection'),
    dcc.Graph(id='graph-content'),
    form
]

@callback(
    Output('graph-content', 'figure'),
    Input('dropdown-selection', 'value')
)
def update_graph(value):
    dff = df[df.country==value]
    return px.line(dff, x='year', y='pop')

if __name__ == '__main__':
    app.run(debug=True)

and I am on python 3.12 and have mantine 0.14.3

RenaudLN commented 6 months ago

Hey there, yes with dash-mantine-components>=0.14 you need a MantineProvider to wrap your app. See the DMC docs for more info on how to get started/migrate 🙂

maxschulz-COL commented 6 months ago

Awesome, thanks :)! It might be good to have an e2e example with an actual dash app in the github README so that other newcomers do not do the same mistake as myself. Would you be interested in me contributing that?

RenaudLN commented 6 months ago

There is already a usage.py in this very repo 😉

maxschulz-COL commented 6 months ago

Makes sense! I for one didn't spot that so a link might help. As I said, if you think that would be useful, happy to contribute!

RenaudLN commented 6 months ago

Thanks for the suggestion, I added a link in the Readme. Happy to take contributions in general though!