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

Markdown does not update code component properly after callback update. #2895

Open
athioak7 opened this issue Jun 20, 2024 · 3 comments · May be fixed by #2909
Open

Markdown does not update code component properly after callback update. #2895

athioak7 opened this issue Jun 20, 2024 · 3 comments · May be fixed by #2909
Assignees
Labels

Comments

@athioak7
Copy link

athioak7 commented Jun 20, 2024

I have a dcc.Markdown that I want to update based on user input in a Textarea. Everything works correctly besides the code component, which when edited stops showing the correct colors (and upon further inspection does not assign the correct classes in the html code).

Expected:
The markdown should update the code component properly.

Environment:

dash==2.17.1
dash-core-components==2.0.0
dash-html-components==2.0.0
dash-table==5.0.0
- OS: Windows, Linux
- Browser: Chrome, Firefox 
- Chrome Version 126.0.6478.62, Firefox Version 127.0 (Windows)

Minimal reproducible example:

from dash import Dash, dcc, html, Input, Output

app = Dash(__name__)

app.layout = html.Div([
    dcc.Textarea(value='''def sum(a, b):
    return a+b

sum(2,2)''', id='codeta'),
    dcc.Markdown(id='markdown'),
])

@app.callback(
    Output('markdown', 'children'),
    Input('codeta', 'value')
)
def update_markdown(value) -> str:
    return f'```python\n\n{value}\n\n```'

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

markdown_bug

@CNFeffery
Copy link

CNFeffery commented Jun 20, 2024

@athioak7 alternative:
demo

from dash import Dash, html, Input, Output
import feffery_antd_components as fac
import feffery_markdown_components as fmc

app = Dash(__name__)

app.layout = html.Div(
    [
        fac.AntdInput(
            value="""def sum(a, b):
    return a+b

sum(2,2)""",
            id="codeta",
            mode="text-area",
            autoSize={"minRows": 6, "maxRows": 6},
        ),
        fmc.FefferyMarkdown(id="markdown", codeTheme="a11y-dark"),
    ]
)


@app.callback(Output("markdown", "markdownStr"), Input("codeta", "value"))
def update_markdown(value) -> str:
    return f"```python\n\n{value}\n\n```"


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

related documentations:

https://fmc.feffery.tech/change-code-theme
https://fac.feffery.tech/AntdInput

@AnnMarieW
Copy link
Collaborator

Hi @athioak7

Thanks for reporting. This has been noted in the dash-docs as well.
This was working prior to dash 2.15 and may be related to #2721

@AnnMarieW AnnMarieW added the bug label Jun 20, 2024
@T4rk1n
Copy link
Contributor

T4rk1n commented Jun 26, 2024

Not related to #2721, that was for the python stacktrace not on component level.

@leeagustin leeagustin linked a pull request Jun 28, 2024 that will close this issue
8 tasks
@gvwilson gvwilson self-assigned this Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 participants