Remove custom components

Hello,

I was trying the custom components and I’m not able to remove the object after declared and instantiated.
Ex. I’m trying this example, how can I remove the login form after confirmed login?

Thanks, and have a good day!

Hi @enryls,

First of all, thanks for using Streamlit! and about your inquire you could solve that in different ways.

1 - Modifying the custom component itself so you can do the checking there.
2 - Solving from the python side using SessionState gist

This is an example if we took the second option:

import streamlit as st
import SessionState
import streamlit.components.v1 as components

_material_login = components.declare_component(
    "material_login", url="http://localhost:3001",
)

def rerun():
    raise st.script_runner.RerunException(st.script_request_queue.RerunData(None))

def material_login(title, key=None):
    return _material_login(title=title, key=key)


session_state = SessionState.get(isLoggedIn=False)

USERNAME = "a@a.com"
PASSWORD = "test"

if session_state.isLoggedIn:
   st.balloons() 
   st.header('Yay ! you are logged in')
else:
    logged_in_data = material_login("Insert your account")

    if bool(logged_in_data) and logged_in_data['username'] == USERNAME and logged_in_data['password'] == PASSWORD:
        session_state.isLoggedIn = True
        rerun()
1 Like

Hi @arraydude,
Thanks for your answer, really appreciated.
I changed the react component, but I will try also something like the second example.

Thanks again and have a good day!