dashboardpartialstaipy

Can I change the content of my page on the fly with Taipy?


I need to make some modifications to my dashboard and I wanted to know whether it's possible to make those changes on the fly?


Solution

  • You have the option in Taipy to use partials. They are small blocks of content that can be modified/reloaded dynamically.

    Here is an example:

    from taipy.gui import Gui 
    
    title = 1
    
    md = """
    <|{title}|number|on_change=change_partial|>
    
    <|part|partial={p}|>
    """
    
    def change_partial(state):
        title_int = int(state.title)
        new_html = f'<h{title_int}>test{title_int}</h{title_int}>'
        print(new_html)
        state.p.update_content(state, new_html)
    
    gui = Gui(md)
    p = gui.add_partial("<h1>test</h1>")
    gui.run()