Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reset state of code editor? #42

Open
RafalSkolasinski opened this issue Nov 16, 2022 · 2 comments
Open

How to reset state of code editor? #42

RafalSkolasinski opened this issue Nov 16, 2022 · 2 comments

Comments

@RafalSkolasinski
Copy link

I am wondering how I could reset state of the editor. I found that I could set initial text with value key but updating it later does not seem to change anything. Here is my attempt

import streamlit as st
from streamlit_ace import st_ace


LANGUAGE = "yaml"
THEME = "twilight"

if 'manifest' not in st.session_state:
    st.session_state.manifest = ""

reset = st.button("Reset!")
if reset:
    st.session_state.manifest = ""

print(st.session_state.manifest == "")

content = st_ace(
    value=st.session_state.manifest,
    placeholder="# Paste your manifest here",
    language=LANGUAGE,
    theme=THEME,
    font_size=14,
    tab_size=4,
    min_lines=45,
    auto_update=True,
    key="ace",
)

if content:
    st.session_state.manifest = content
    st.subheader("Content")
    st.code(content, language=LANGUAGE)
@RafalSkolasinski
Copy link
Author

hmmm... I changed by reset button to increment counter linked to st_ace key... This seems to work but not sure this is the best solution?

import streamlit as st
from streamlit_ace import st_ace


LANGUAGE = "yaml"
THEME = "twilight"

if 'state' not in st.session_state:
    st.session_state.state = 0

reset = st.button("Reset!")
if reset:
    st.session_state.state += 1


print(st.session_state.state)

content = st_ace(

    placeholder="# Paste your manifest here",
    language=LANGUAGE,
    theme=THEME,
    font_size=14,
    tab_size=4,
    min_lines=45,
    auto_update=True,
    key=f"ace-{st.session_state.state}",
)

if content:
    st.subheader("Content")
    st.code(content, language=LANGUAGE)

@Franky1
Copy link

Franky1 commented Feb 23, 2023

I would also like to see a built-in fix for this problem, since i also tried to solve how to update the content of the editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants