question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interactive widgets should not output labels if label argument is an empty string

See original GitHub issue

Summary

Since Streamlit 0.83, all the interactive widgets (except for streamlit.radio) outputs a <label> element for the widget even if the label value is an empty string. Before 0.83, setting a widget’s label to an empty string left out the <label> element.

The current behaviour results in unwanted vertical whitespace before a widget for empty labels.

Steps to reproduce

Code snippet:

import streamlit as st

for widget in (st.text_input, st.number_input, st.date_input, st.time_input, st.slider, st.color_picker, st.text_area):
    st.subheader(widget.__name__)
    c1, c2 = st.beta_columns(2)
    with c1:
        widget("Label")
    with c2:
        widget("")

for widget in (st.selectbox, st.radio, st.multiselect, st.select_slider):
    st.subheader(widget.__name__)
    c1, c2 = st.beta_columns(2)
    with c1:
        widget("Label", ["A", "B", "C"])
    with c2:
        widget("", ["A", "B", "C"])

The code snippet shows the differences for all the interactive widget. But, here’s a select screenshot showing the differences between 0.82 and 0.84 for streamlit.selectbox and streamlit.radio. In Streamlit 0.84, only streamlit.radio works the same as before. Everything else outputs empty <label> elements.

Streamlit 0.82:

82

Streamlit 0.84:

84

Expected behavior:

All the widgets should omit outputting labels if the label argument is an empty string.

Actual behavior:

The streamlit.radio widget is the only one that does not output empty labels.

Is this a regression?

The current behaviour was introduced in Streamlit 0.83.

Debug info

  • Streamlit version: Streamlit, version 0.84.2
  • Python version: Python 3.8.11
  • Using Conda? PipEnv? PyEnv? Pex? Just pip
  • OS version: Debian buster (in a python:3.8 container)
  • Browser version: Safari 14.1 on macOS Mojave 10.14.6

Additional information

None.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kinghuangcommented, Aug 3, 2021

The issue’s a bit complicated, because it seems the empty <label> elements were intentionally added in #3317, in response to #3220. That PR optimizes for alignment across columns, but reverses past behaviour and gets in the way for other layouts.

I’m hiding the empty labels for now with a bit of css.

label:empty { display: none }
0reactions
kajarenccommented, Sep 13, 2022

Hey, this is fixed now with the label_visibility param, that we add for all widgets with labels.

We encourage to always use a meaningful labels for accessibility reasons

But now you can use keyword argument label_visibility="hidden" to hide label or label_visibility="collapsed" to collapse whitespace completely.

This feature will be available on streamlit 1.13.0 (or you can use it now with streamlit-nightly

Read more comments on GitHub >

github_iconTop Results From Across the Web

12 Labels and Buttons
These visual and interactive features provide the cornerstone for many widgets in the Motif toolkit, such as CascadeButtons, DrawnButtons, and ToggleButtons.
Read more >
Alignment of widgets in a row if they are of different types is ...
Summary When widgets of different types are placed in columns within ... should not output labels if label argument is an empty string...
Read more >
1. Labels in Tkinter
Hello Tkinter Label. We will start our tutorial with one of the easiest widgets of Tk (Tkinter), i.e. a label. A Label is...
Read more >
ipywidgets Documentation
Question: When I display a widget or interact, I just see some text, such as IntSlider(value=0) or interactive(children=(IntSlider(value=0, ...
Read more >
Output Widgets
Add Labels​​ This will create a label widget to display text in the GUI. The title is used to uniquely identify the label,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found