Cannot display charts in one go when generating them via a loop

Hello,

I am new to streamlit and I wanted to display a bunch of graphs on one of the pages. The code below works but it seems to display the graphs sequentially rather than all 18 graphs in one go. So when I switch between tabs it needs to rerun and take time to display all 18 graphs. Can you please help ne display all graphs once and for these graphs to stay static and not be refreshed after?
Thanks

import streamlit as st
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from datetime import date, timedelta

---- Sidebar Navigation ----

st.sidebar.title(“Navigation”)
page = st.sidebar.radio(“Go to”, [“:bar_chart: Overview”, “:coin: Sales Data”])

---- Page: Overview ----

if page == “:bar_chart: Overview”:
st.title(“:bar_chart: Overview”)
st.write(“Welcome to the overview page! Here’s a sample dataset and a simple bar chart.”)

---- Page: Sales Data (With 3x2 Chart Layout) ----

elif page == “:coin: Sales Data”:
st.title(“:coin: Sales Data”)
st.write(“This section displays multiple sales-related charts in a grid layout.”)

# Generate Sample Data
def create_chart(x,y_data, title):
    fig, ax = plt.subplots()
    ax.plot(x, y_data, marker="o", linestyle="-")
    ax.set_xlabel("Days")
    ax.set_ylabel("Values")
    ax.set_title(title)
    return fig

@st.cache_data
def generate_charts(num_plots):
    x = np.arange(1, 11)  # X-axis (Days: 1 to 10)
    return [create_chart(x, np.random.randint(10, 100, size=len(x)), f"Chart {i+1}") for i in range(num_plots)]


num_plots = 18  # Total charts
charts = generate_charts(num_plots)  # **Cached charts**


with st.container():
    for i in range(0, num_plots, 3):  # 3 charts per row
        cols = st.columns(3)
        for j in range(3):
            if i + j < num_plots:
                with cols[j]:
                    st.pyplot(charts[i + j], clear_figure=True)

I also tried the following but it did not change anything:

@st.cache_data
def generate_charts(num_plots):
    x = np.arange(1, 11)  # X-axis (Days: 1 to 10)
    return [create_chart(x, np.random.randint(10, 100, size=len(x)), f"Chart {i+1}") for i in range(num_plots)]


num_plots = 18  # Total charts
charts = generate_charts(num_plots)  # **Cached charts**

with st.container():
    for i in range(0, num_plots, 3):  # 3 charts per row
        cols = st.columns(3)
        for j in range(3):
            if i + j < num_plots:
                with cols[j]:
                    st.pyplot(charts[i + j], clear_figure=True)