ObservedObserver / streamlit-shadcn-ui

Using shadcn-ui components in streamlit
https://shadcn.streamlit.app/
MIT License
759 stars 57 forks source link

How to extract value when using `element` #32

Open qingant opened 4 months ago

qingant commented 4 months ago
with ui.element('div', className='w-full flex flex-row justify-between items-center', key='container') as div:
  print('DIV', div)
  a = ui.element('tabs', options=['All', 'Running', 'Ended'], default_value='All', className='mr-2', key='status_tabs')
  b = ui.element('tabs', options=['All', 'Winning', 'Losing'], default_value='All', className='mr-2', key='result_tabs')
  c = ui.element('div', className='flex-grow w-full')
  d = ui.element('input', placeholder='Search Experiment', className='border-none w-[50px] p-2 searchInput', key='search')

print(div,  div.state, div.key, div.children[0].key, d.state, d.value)

I have a piece of code like this, but unfortunately the value is actually populated to div.state. how could I get value of each element ? or at least have a way to figure out which element the value comes from ?

Yemeen commented 3 months ago

From the experimental section of the docs

Another task to complete before making element a formal feature involves the handling of element values. When using nested elements, they share the same iframe and Streamlit values in the session state. Therefore, I need to slightly refactor the current value type to include the component key, allowing all components to share a single Streamlit value.