-
-
Save treuille/e8f07ebcd92265a68ecec585f7594918 to your computer and use it in GitHub Desktop.
import streamlit as st | |
import pandas as pd | |
# Load some example data. | |
DATA_URL = \ | |
"http://s3-us-west-2.amazonaws.com/streamlit-demo-data/uber-raw-data-sep14.csv.gz" | |
data = st.cache(pd.read_csv)(DATA_URL, nrows=1000) | |
# Select some rows using st.multiselect. This will break down when you have >1000 rows. | |
st.write('### Full Dataset', data) | |
selected_indices = st.multiselect('Select rows:', data.index) | |
selected_rows = data.loc[selected_indices] | |
st.write('### Selected Rows', selected_rows) |
super cooooooool
Thanks @dariushazimi!
If I want to select only one row and make that its own df that I can populate some dropdown menus and sliders, should I just say:
st.select?
Another way to put it, can I select a row that will populate dropdown menus and sliders?
@acidicph: I‘d use a select box for that. Please also not that “row-selectable dataframe” will be on of our launch examples for custom components when that comes out. Have fun building apps! 🥳
Hi, again! Is there a way to input instead of selecting a row based on certain ID because my dataframe is a 100k row
@treuille I think I got around that by letting user input an ID and grabbing the whole row, I think selecting might be a bit too much given that I have a100k of them. My goal is to let the user simulate based on new input that they can adjust and that is passed through a ML model that is pickled along the code. I am having trouble with the part where after grabbing a row from the data frame, "populating" it in a slider and whatnot, as soon as I change it to a new value, the page restarts back. Here is a snippet of my code, could you please guide me onto how to solve this:
st.subheader("Simulate")
file_name = "train_input_test.csv"
input_id = st.text_input("Enter ID", "")
if st.button("Search by Id"):
IDS = [input_id]
with open(file_name, newline='') as csvfile:
reader = csv.DictReader(csvfile)
rows = [row for row in reader if row['encounter_ID'] in IDS]
if rows:
#st.write(rows)
new_time_in_hospital = st.slider("Time in hospital",1,14,int(rows[0]['time_in_hospital']),None,None)
new_num_medications = st.slider("Number of Medication",1,81,int(rows[0]['num_medications']))
new_num_procedures = st.text_input("time_in_hospital", rows[0]['num_procedures'])
if st.button("Generate New CSV"):
new_file_name = "new" + file_name
out_put_file = writer(open(new_file_name, "w"), newline='')
with open(file_name, "r") as f:
read = csv.reader(f)
for new_row in read:
st.write(new_row)
if new_row['encounter_ID'] in IDS:
new_row['time_in_hospital'] = new_time_in_hospital
out_put_file.writerow(new_row)
Right now, you need to use a separate GUI element to select the row, which is what this gist shows. When we get the row-selectable dataframe, you will be able to select directly. If you have further questions about how to solve this scenario via Streamlit I would suggest the forums (discuss.streamlit.io) where a lot of people besides me can help you out! :)
…
On Wed, Jun 10 2020 at 12:58 PM, Ebrahim H Ghazvini Zadeh < @.*** > wrote: @.**** commented on this gist. Hi, again! Is there a way to input instead of selecting a row based on certain ID because my dataframe is a 100k row — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub ( https://gist.github.com/e8f07ebcd92265a68ecec585f7594918#gistcomment-3337540 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAMYONLF7MSMRWYOJ6U2KDDRV7QXBANCNFSM4JHBEHTA ).
Alright, thank you.
This gist gives a workaround to select rows from a table. You can test it out by running:
And you should see something like this: