How to create a page in the code?

β€œI am familiar with creating a multi-page app using Streamlit. However, I am now want to know how to dynamically create new pages in real-time instead of having to create a .py script in advance in the pages folder. Can anyone guide me on how to implement a functionality where clicking a button would generate a new page?”

st.markdown(f"<a href='{project_id}' target='_blank'>{project_id}</a>", unsafe_allow_html=True)

Here, the detail page is dynamic, based on the corresponding project_id.

Here’s one way to do it

from pathlib import Path

import streamlit as st

page_name = st.text_input("Page name", "page2")

if page_name and st.button("Create new page"):
    (Path("pages") / f"{page_name}.py").write_text(
import streamlit as st

st.write("Hello from {page_name}")