import streamlit as st # Create item custom_item = form_cols[1].text_input(label="Custom item") custom_item_submit = form_cols[1].button("Add to database", key="new_item_input_case_" + str(case_n) + "_layer_" + str(index)) # if saving the custom item if custom_material_submit: st.session_state["custom_items_database_active"].insert_rows(idx=2) # add a new row before inserting custom item st.session_state["custom_items_database_active"].cell(row=2, column=1, value=custom_item) # insert custom item into new row (INSERT AND ROW SHOULD BE SAME VALUE) st.session_state["custom_materials_database_write"].save("/path/to/Excel.xlsx") # save the file to reflect the changes next time the database is loaded # get_custom_database() # TODO make global function? Attempt to show changes after adding # custom_item_panda = pd.DataFrame([custom_item]) # to see the changes get reflected in the form # all_custom_item = custom_item_panda.append(all_item_list_pandas, ignore_index=True) # materials_choices = customization_choices.append(all_custom_materials, ignore_index=True) form_cols[1].write("\"" + str(custom_item) + "\" has been added to the database. Please select a different item to see the changes") # Edit item # First check if selected material is custom-made or not if orig_material_name in st.session_state["orig_item_prefill_index"]: form_cols[1].info("Sorry, you can only change custom-made items.") elif orig_material_name in st.session_state["custom_item_prefill_index"]: to_change = form_cols[1].text_input(label="Edit material name", value=orig_item_name) if form_cols[1].button("Save changes"): st.session_state["custom_item_database_active"].cell(row=st.session_state["custom_item_prefill_index"][orig_item_name]+2, column=1, value=to_change) st.session_state["custom_item_database_write"].save(st.session_state["custom_database_path"]) form_cols[1].info("\"" + to_change + "\" has been saved to the database. Please select a different item to see the changes reflect.") # TODO push new changes to form for immediate change view # item_table_pandas = pd.DataFrame(item_table_active.values) # custom_item_list = customize_options.append(item_table_pandas, ignore_index=True)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter