HTML escape on hovertemplate plotly

Locally app

Hello I’m trying to display image on a plotly plot but streamlit seems to always escape the HTML even with auto unsafe_allow_html to TRUE :confused:

Here’s my code :

for index, row in pokepos_sorted.iterrows():
    number = row['NUMBER'] - 1
    sprite = pokesprites['SPRITE_NAME'].iloc[number]
    sprite_src = "/workspaces/pokedata-jroose11/sprites/" + sprite
    value = row[Stats]
    dtypes = row['DTYPES']
    colordt_left = dt_type_pal_new_double.get(dtypes)[0]
    colordt_right = dt_type_pal_new_double.get(dtypes)[1]
    hover_template = f'<img src="{sprite_src}" alt="{row["POKEMON"]} Image" width="100" height="100"><br>{row["POKEMON"]} <br>{dtypes}'
    
    if dtypes not in legend_labels_pos:
        scat_pos = go.Scatter(
            x=[row['POSITION']],
            y=[value],
            mode='markers',
            marker=dict(
                color=colordt_left,
                symbol='circle',
                size=10,
                line=dict(width=3, color=colordt_right)
            ),
            name=dtypes,
            text=row['POKEMON'] + '<br>' + dtypes,
            hoverinfo='text',
            hovertemplate=hover_template
        )
        fig_pos.add_trace(scat_pos)
        legend_labels_pos.add(dtypes)
    else:
        scat_pos = go.Scatter(
            x=[row['POSITION']],
            y=[value],
            mode='markers',
            marker=dict(
                color=colordt_left,
                symbol='circle',
                size=10,
                line=dict(width=3, color=colordt_right)
            ),
            showlegend=False,
            name=dtypes,
            text=row['POKEMON'] + '<br>' + dtypes,
            hoverinfo='text',
            hovertemplate=hover_template
        )
        fig_pos.add_trace(scat_pos)

To had complexity, I can plot images with st.image() but not with st.write or st.markdown even with unsafe_allow_html = True and with
[server]
enableStaticServing = true

And my png in the static file.

I’m coding on codespace but I also tried on a pycharm kubuntu 22.04 and same result :cry:

Does this code run in a local notebook? I can’t get Plotly to render images locally with your code, so I’m thinking plotly just can’t render images in the hover template.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.