Adding a streamlit component into a markdown block

I have a custom markdown block that shows some information like user profile

import streamlit as st

# Define CSS style
st.markdown("""
    <style>
    .profile-section {
        background-color: #f9f9f9;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        padding: 20px;
        font-family: Arial, sans-serif;
        width: 100%;
        max-width: 400px;
    }
    .profile-section h2 {
        font-size: 18px;
        color: #333333;
        margin-top: 0;
    }
    .profile-section .profile-item {
        margin-bottom: 15px;
        font-size: 16px;
        color: #555555;
    }
    .profile-section .profile-item label {
        font-weight: bold;
        color: #888888;
    }
    .profile-section .profile-item a {
        color: #ff6f61;
        text-decoration: none;
    }
    .profile-section .profile-item a:hover {
        text-decoration: underline;
    }
    </style>
    """, unsafe_allow_html=True)

# Display profile information using HTML
st.markdown("""
<div class="profile-section">
    <h2>Personal Information</h2>
    <div class="profile-item">
        <label>Facebook:</label> <a href="https://facebook.com" target="_blank">View</a>
    </div>
    <div class="profile-item">
        <label>Mobile phone:</label> +1-541-754-3010
    </div>
    <div class="profile-item">
        <label>Tax residence:</label> United States
    </div>
    <div class="profile-item">
        <label>Series and number of passport:</label> CO3005978
    </div>
</div>
""", unsafe_allow_html=True)

Is there a way to add a streamlit component like st.metric into the block?

This is followup question from a previous post. POsting as new topic as previous topic was closed.

@Encrypt

Thanks for your previous response. This is a followup question since the topic was closed.

The short answer is no, you can’t insert a Streamlit component into Markdown. You can custom script out HTML to and behave how you want, even copying from the HTML that st.metric generates, but the Streamlit commands are modular: the st.markdown command creates a distinct element from the st.metric command. Only layouts can contain other Streamlit elements.

1 Like

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