Milind Kamat commited on
Commit
0ad02c4
·
1 Parent(s): ca54b24

2024 dec 30 method update

Browse files

Signed-off-by: Milind Kamat <36366961+milindkamat0507@users.noreply.github.com>

Files changed (1) hide show
  1. app.py +31 -28
app.py CHANGED
@@ -347,59 +347,62 @@ class StreamlitTutorial:
347
 
348
 
349
  def get_input_elements(self) -> List[Tuple[str, str]]:
350
- """Cross-validated collection of input widgets with unique keys"""
 
 
351
  return [
352
  ("Text Input", """st.text_input('Enter your name',
353
- key='input_example_1_a',
354
  placeholder='John Doe')"""),
355
 
356
  ("Text Area", """st.text_area('Enter long text',
357
- key='area_example_1_b',
358
  height=100,
359
  placeholder='Write something...')"""),
360
 
361
  ("Number Input", """st.number_input('Enter a number',
362
- key='number_example_1_c',
363
  min_value=0,
364
  max_value=100,
365
  value=50,
366
  step=5)"""),
367
 
368
  ("Slider", """st.slider('Select value',
369
- key='slider_example_1_d',
370
  min_value=0,
371
  max_value=100,
372
  value=50,
373
  step=5)"""),
374
 
375
  ("Select Box", """st.selectbox('Choose an option',
376
- key='select_example_1_e',
377
  options=['Option 1', 'Option 2', 'Option 3'],
378
  index=0)""")
379
  ]
380
-
381
-
382
- def render_input_elements(self, col: st.delta_generator.DeltaGenerator) -> None:
383
- """Cross-validated rendering method with proper key handling"""
384
- with col:
385
- st.markdown("### 📝 Code Examples")
386
- for idx, (title, code) in enumerate(self.get_input_elements()):
387
- # Create unique container key
388
- example_container_key = f"example_container_{idx}"
389
- output_container_key = f"output_container_{idx}"
 
 
390
 
391
- with st.container(border=True, key=example_container_key):
392
- st.markdown(f"**{title}**")
393
- st.code(code)
394
- st.markdown("Live output:")
395
-
396
- with st.container(border=True, key=output_container_key):
397
- try:
398
- # Execute the code with unique keys
399
- exec(code)
400
- except Exception as e:
401
- st.error(f"Error: {str(e)}")
402
-
403
 
404
 
405
 
 
347
 
348
 
349
  def get_input_elements(self) -> List[Tuple[str, str]]:
350
+ """
351
+ Cross-validated collection of input widgets with unique keys
352
+ """
353
  return [
354
  ("Text Input", """st.text_input('Enter your name',
355
+ key='text_input_demo_1',
356
  placeholder='John Doe')"""),
357
 
358
  ("Text Area", """st.text_area('Enter long text',
359
+ key='text_area_demo_1',
360
  height=100,
361
  placeholder='Write something...')"""),
362
 
363
  ("Number Input", """st.number_input('Enter a number',
364
+ key='number_input_demo_1',
365
  min_value=0,
366
  max_value=100,
367
  value=50,
368
  step=5)"""),
369
 
370
  ("Slider", """st.slider('Select value',
371
+ key='slider_demo_1',
372
  min_value=0,
373
  max_value=100,
374
  value=50,
375
  step=5)"""),
376
 
377
  ("Select Box", """st.selectbox('Choose an option',
378
+ key='select_box_demo_1',
379
  options=['Option 1', 'Option 2', 'Option 3'],
380
  index=0)""")
381
  ]
382
+
383
+ def render_input_elements(self, col: st.delta_generator.DeltaGenerator) -> None:
384
+ """
385
+ Renders input examples with unique keys for both examples and live output
386
+ """
387
+ with col:
388
+ st.markdown("### 📝 Code Examples")
389
+ for idx, (title, code) in enumerate(self.get_input_elements()):
390
+ with st.container(border=True, key=f"demo_container_{idx}"):
391
+ st.markdown(f"**{title}**")
392
+ st.code(code)
393
+ st.markdown("Live output:")
394
 
395
+ with st.container(border=True, key=f"output_container_{idx}"):
396
+ try:
397
+ # Create runtime version with unique key
398
+ runtime_code = code.replace('demo_1', f'runtime_{idx}')
399
+ exec(runtime_code)
400
+ except Exception as e:
401
+ st.error(f"Error: {str(e)}")
402
+
403
+
404
+
405
+
 
406
 
407
 
408