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

Closed
athioak7 opened this issue Jun 20, 2024 · 3 comments · Fixed by #2909
Closed

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

athioak7 opened this issue Jun 20, 2024 · 3 comments · Fixed by #2909
Labels
bug something broken P3 backlog

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
Contributor

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 something broken 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.

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

Successfully merging a pull request may close this issue.

5 participants