I have a history log coded using a Dash html.Pre with multiple html.Span components, each span is for a history entry. This list is huge and I’m trying to find a way to only partially update (append or prepend) this log when the time is moving forward. Tried Patch but didn’t work.
Does Patch work with normal html components like html.Pre?
Yes, it should work with any dash component.
That’s great! Could you tell me how to use Patch to update an html.Pre’s children property, which is a list of html.Span? I use a callback to output to its children property, but nothing get updated if I use Patch. My code looks like this:
app.layout = html.Div(
html.Pre(["History log"], id="history-log")
new_entries = [...]
patched_history_log = Patch()
I didn’t think that pre was a list of spans, I always thought it was just text which maintained the formatting and spacing that it is given.
That being said, the list most likely the reason it is not working the way you intend to.
Do you have the code for how you initially populate the info?
If you want to add children, I’d recommend maybe using a div and filling html.Pre as children into it.
Please post a MWE demonstrating the issue. That’ll make it easier for people to help
Looking at your code snippet, I see one potential issue. You seem to be adding a list to a list, in which case you should use an ‘extend’ rather than an ‘append’ operation.
Yes, you’re right. I mistakenly added a list to a list. After fixing this, my log updates perfectly.
Thank you very much!