[Python] How to use resolved output string from codechunk into markdown quarto?

Discussão em 'Python' iniciado por Stack, Janeiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    This can also be framed as "How to view dynamic(names stored in variable) html files in markdown documents like quarto ?

    I have some html plot files with unique ids that I want to include in the notebook and names of those plots are in variables/parameters and I have to view them in quarto notebook (similar to jupyter markdown notebook).

    for example variable corr_net_graph contains the plot name like: plot_userid.html

    so to view the plot if it is static name then using below code works:

    ```{=html}
    <iframe width="900" height="1200" src="plot_user123.html"></iframe>
    ```


    but how do I make this work for dynamic names in variables ?

    I have tried below method but that doesn't work

    ```{python}
    iframe_str = '<iframe width="900" height="1200" src='+str(corr_net_graph)+'></iframe>'
    ```

    ```{=html}
    iframe_str
    ```


    So I am not able to evaluate this into the iframe string in html cell or in markdown.

    Appreciate any help or suggestions.

    Update: I have also tried using pyscript

    ```{python}
    import pyscript
    ```

    ```{=html}
    <iframe width="900" height="1200" src='<pyscript>corr_net_graph</pyscript>'></iframe>
    ```


    ```{=html}
    <iframe width="900" height="1200" src=<py-script>{corr_net_graph}</py-script>></iframe>
    ```


    ```{=html}
    <iframe width="900" height="1200" src=<py-script>f"{corr_net_graph}"</py-script>></iframe>
    ```
    checked inspect elements on this and got:


    [​IMG]

    Continue reading...

Compartilhe esta Página