Multiple Page App Side Bar Icon

  1. Is there any way to use the icons which ı select for the sidebar in multiple page app. I want to make sidebar like the below image:
    Adsız

  2. Can I use the input variable that I get when I press a button on a page in a multiple page application without any problem on the other page?
    I tried to do this by changing the single interface, but an unsolvable problem occurred. I’m asking for an alternative method.
    The Issue:
    The problem of not using the return value of the function inside the other function in Streamlit, Python

  3. Is there a function in streamlit to hide the appearance of interface created with a python function a (def) like a st.hide_interface(function_name) > The function works as always ,only the inferface doesn’t seem.

Hi @murat_tasci,

  1. You can do that currently by putting emojis in the filenames, as shown here Introducing multipage apps! 📄. We’re hoping to add alternate option for adding emojis, but for now that’s the way to add them.

  2. In general, if you have a variable that you want to exist across multiple pages, than using st.session_state is a good option Session State - Streamlit Docs

page 1:

if st.button():
    st.session_state["file_path"] = "123/456/file.csv"

page 2:

if "file_path" in st.session_state:
    st.write(st.session_state["file_path"])
  1. Can you explain what you mean by an interface?

Thank you for answer @blackary A problem arises when there are interfaces that need to change one after the other and a variable taken from the first interface needs to be used in the other interface. Somehow this is not possible.

If we have a streamlit property like st.hide_interface (python_function’s_name_including_an_interface) and call the python function and just hide its interface, we can run the function without any problem for variable assignment, variable obtaining. This way the problem of overlapping interfaces can be avoided where we need to call the same function twice.
For Example:
def interface1():
#some interface codes
def interface2():
#some interface codes
#getting input variable and variable assignment codes >line2

st.hide_interface (interface2) > This feature will hide its interface for def interface2() and run the code in line2

Hi @murat_tasci,

I still don’t quite understand what you mean by an interface – do you mean something like an st.text_input, or some other visible widget? Or do you mean something like an API?

I was talking about the structure of visible widgets in web application with interface term

Do you mean something like this? Typically the way you can hide a part of the UI is by putting it inside of a conditional statement that depends on a widget or some session state.

import streamlit as st

def interface1():
    st.write("interface1")

def interface2():
    st.write("interface2")

if st.checkbox("Show interface 1"):
    interface1()
else:
    interface2()
#Libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
import fitz 
import io
import streamlit as st

global path_input_0    #HERE ASSIGNMENTS-------------------------------
path_input_0=""
path_input_last=""

def login():
  
    # interface codes for the login screen 
   # (css,buttons,background,input area etc )
    path_input_0 =st.text_input("File Path:", "Please enter the path to the folder containing the Abstract_Account_Web_App.py file")
    st.write(path_input_0)
    global proceed
    if st.button("Proceed"):
        st.session_state["page"] = "main"
        st.balloons()
        st.experimental_rerun()
    return path_input_0


def main():
    # interface codes for the main screen 
    # (css,input,buttons etc.)
    
    pathz=path_input_last+"/Bankomat Alışveriş Özeti.pdf"
    st.write("path1:",pathz)
    file_names = [r'%s' % pathz]
    st.write(file_names)



        

    
if __name__=='__main__':
               
    if "page" not in st.session_state:
                  st.session_state["page"] = "login"
    
    if st.session_state["page"] == "login":
                 
                  path_input_last=login()
                  st.write("last:",path_input_last)
                  
     
    elif st.session_state["page"] == "main":
                  st.balloons()
                  main()

İf I call login inside the main function again, I can get the variables which I want (path_input_last , path_input_0 ) but this time the problem of calling the two interfaces together arises. (main and login screens’s overlapping). It breaks this as my goal is to fetch the interfaces in order At this point, I thought that a feature like st.hide_interface(function_name) might find a solution to my problem.

@murat_tasci Thanks for the code! Just an FYI, you share code like that, it is much easier to read and copy if you put it between pairs of 3 ` symbols like this:

```
Put code here
```

I think the best solution to your problem will be to use st.session_state to store the file paths, rather than using global variables. You can automatically make the text_input send the value to session state by giving it a key, like in the example below.

# Libraries
import io
import os

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import streamlit as st


def login():
    # interface codes for the login screen
    # (css,buttons,background,input area etc )
    path_input_0 = st.text_input(
        "File Path:",
        "Please enter the path to the folder containing the Abstract_Account_Web_App.py file",
        key="PATH_INPUT_LAST",
    )
    st.write(path_input_0)
    global proceed
    if st.button("Proceed"):
        st.session_state["page"] = "main"
        st.balloons()
        st.experimental_rerun()


def main():
    # interface codes for the main screen
    # (css,input,buttons etc.)

    pathz = st.session_state["PATH_INPUT_LAST"] + "/Bankomat Alışveriş Özeti.pdf"
    st.write("path1:", pathz)
    file_names = [r"%s" % pathz]
    st.write(file_names)


if __name__ == "__main__":
    if "page" not in st.session_state:
        st.session_state["page"] = "login"

    if st.session_state["page"] == "login":
        login()
        st.write("last:", st.session_state["PATH_INPUT_LAST"])

    elif st.session_state["page"] == "main":
        st.balloons()
        main()

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.