TangleSpace / hydralit_components

A package of custom components for Streamlit and Hydralit. Can be used directly or in combination with the Hydralit package.
Apache License 2.0
185 stars 21 forks source link

Navbar menu link to external webpage #14

Closed SivamPillai closed 2 years ago

SivamPillai commented 2 years ago

First of all, thank you for this easy-yet-powerful component! It makes my streamlit app a lot more capable!

Is there a way for the navbar links to point to an external webpage (or is there a hack to achieve this)?

I would like one of my menus say Google, to navigate to https://google.com in the same tab.

I am thinking of using st.markdown to achieve this but not quite sure how.

Thanks for your help!

TangleSpace commented 2 years ago

Thanks for the kind words. Absolutely you can do what you are thinking, there is one big issue though, due to the way Streamlit does same origin security, if you use an iFrame it will not load properly usually if the site has HTTPS enabled, as the security policy prevents the page from loading, hence the Streamlit approach is to open the page into a new tab.

You can create an entry on the navbar as usual and add code like this to load the page into an iFrame.

import streamlit.components.v1 as components

if navbar_output == 'Google':
    components.iframe("https://www.google.com")

Hope that helps.