Bokhe session mangement while interagiton panel dahboard with flask

I have created a panel dashboard and I want to integrate it with a Flask app. I have had some success in doing so, but I encountered a problem. When a user logs out and reloads the panel dashboard, it does not appear and instead shows an error message.
RuntimeError: Models must be owned by only a single document, ImportedStyleSheet(id=’p1007′, …) is already in a doc
500 GET /bkapp/autoload.js?bokeh-autoload-element=ff952a09-a902-4d77-91fb-1d058116d66c&bokeh-app-path=/bkapp&bokeh-absolute-url=http://localhost:5007/bkapp (::1) 549.87ms
while i run the code which as

`
# Bokeh application handler
def modify_doc(doc):
    dashboard = JiraDashboard()  # Instantiate your Panel dashboard or components
    pn_dashboard = pn.Column(  # Create a Panel layout
        pn.Row(dashboard.param, dashboard.update_charts),  # Add parameters and update controls
        dashboard.worklog_chart()  # Display the worklog chart
    )
    doc.add_root(pn_dashboard.get_root())

# Function to find an available port
def find_available_port(port):
    while True:
        try:
            with socket.create_connection(('localhost', port), timeout=1):
                port += 1
        except socket.error:
            return port

# Initialize Bokeh server with an available port
bk_server_port = find_available_port(5006)
bk_server = None
bk_worker_thread = None

def start_bokeh_server():
    global bk_server, bk_worker_thread
    bk_server = Server({'/bkapp': modify_doc}, io_loop=IOLoop(), port=bk_server_port, allow_websocket_origin=["localhost:5000","127.0.0.1:5000"])

    # Bokeh server worker
    def bk_worker():
        bk_server.start()
        bk_server.io_loop.start()

    bk_worker_thread = Thread(target=bk_worker)
    bk_worker_thread.daemon = True

@app.route('/dashboard')
def dashboard():
    if 'google_token' not in session:
        return redirect(url_for('login'))

    # Ensure that the Bokeh app is started on a separate thread
    if not bk_worker_thread.is_alive():
        bk_worker_thread.start()

    script = server_document(url=f'http://localhost:{bk_server_port}/bkapp')
    return render_template_string(f'''
        <!doctype html>
        <html>
        <head>
            <title>Dashboard</title>
        </head>
        <body>
            <h1>Panel Dashboard</h1>
            {script}
            <a href="/logout"><button>Logout</button></a>
        </body>
        </html>
    ''')

def reload_dashboard():
    global bk_server, bk_worker_thread
    if bk_server:
        bk_server.io_loop.add_callback(bk_server.io_loop.stop)
        bk_worker_thread.join()
    start_bokeh_server()`

I try to close the broken session when the user logs out. I use the session_id for the broken session but did not see any positive impact.

New contributor

Abhinandan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật