streamlit: streamlit.bar_chart should not sort columns.
Summary
streamlit.bar_chart(some_data_frame) will sort index values of some_data_frame before displaying. This prevents users from sorting by e.g. values.
Steps to reproduce
streamlit.bar_chart(some_data_frame) with a DataFrame that isn’t sorted by columns.
Expected behavior:
Streamlit to maintain sort order.
Actual behavior:
Streamlit sorts by column.
Is this a regression?
No
Debug info
- Streamlit version: Streamlit, version 0.47.4
- Python version: Python 3.7.4
- PyEnv
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 21 (2 by maintainers)
Experiencing the same issue here. Not sure how this could be considered not a bug. There is no reason that every bar chart should be sorted by their index column as it severely limits the usability of the built in bar_chart. The API also has not been updated in any way to reflect this unusual behavior in the 4 years since this bug was closed.
same but it seems to me that it’s not a bug, but feature, bad feature. It would be very nice if developers add to bar_chart argument ‘order’, that will change order of bars
Just a heads up to anyone using the Altair workaround and trying to get the chart to use the full width of the container like a regular
stsyntax would.I used
st.writeas per workaround, which would produce an Altair chart of width 300px. Following Altair docs I tried setting `.properties(width=‘container’) but this made the chart disappear.Instead of
st.write()I swapped it out forst.altair_chart()as per st.altair_chart documentation and passeduse_container_width=Trueand that gave me the scaling behavior I was looking for.My code for reference:
Im using
plotlyto make the plots instead of builtin functionHi @dcaminos
I believe the original bug report is correct. Let’s consider the following example. I have a dataframe with the following data. It has already been sorted according to the average_salary column.
I show the table and the chart using this code:
Output:
As you can see, the chart sorts the x axis alphabetically, leading to inconsistent results. The expectation is that it should leave the order of the elements untouched. Please reopen the bug if you agree.
same problem !
same problem
same problem.
Same Issue…