streamlit-option-menu icon indicating copy to clipboard operation
streamlit-option-menu copied to clipboard

Is it possible to add options dynamically?

Open chiehpower opened this issue 2 years ago • 2 comments

hi all,

Thanks for providing this awesome component!! It is very helpful for me.

I have one question after I dived into this component.

There are 4 options (items) in my menu list (home, models, inference, project).

image

For each option, there are several sub-options inside. For example, there are 3 options in models such as download, upload, and check status.

So I expect that the mean option can be extended dynamically when I click the specific option.

image

The download and upload will only be displayed in the Models option.


Postscript, I have one idea for sharing. I am not sure whether there is any chance to add one feature in streamlit-option-menu so that we can add the sub-option for each parent option. The image below is my concept that when users click the parent option, it is able to extend the child option.

image

Thank you! BR, Chieh

chiehpower avatar Apr 07 '22 07:04 chiehpower

Since all menu items are dynamically updated when an item is clicked, you can always change the submenu items (which you indent and style using CSS) below the selected item.

victoryhb avatar Apr 08 '22 17:04 victoryhb

Would you like to provide a very simple example?

I have no idea how to handle the callback in this part...

Thank you!!

chiehpower avatar Apr 11 '22 02:04 chiehpower

you should be able to modify list of options by using key on option_menu - this way selection will be stored in st.session_state, which you can check right before showing the menu to modify it.

But the problem is, it's not embedded submenu items. So once you click one of those - your selection will be changed to that item and on redraw that will cause issues likely.

What I'm doing instead is 2 option_menus. One on sidebar with main options, 1 on top - with sub options.

There's an issue asking for submenu items too.

CHerSun avatar Sep 16 '22 10:09 CHerSun

Or it might be possible to draw menu in container (st.empty in this case) and update it later in code (this approach didn't work nicely in my attempts)

CHerSun avatar Sep 16 '22 10:09 CHerSun

Got it!! Thanks for your reply!!

In the end of the day, I changed to using streamlit-elements to resolve my requirements. However, using streamlit-option-menu can be easily and rapidly applied in most situations.

Thanks for your contributions to open source!

chiehpower avatar Sep 20 '22 07:09 chiehpower