Streamlit Ace Editor Component

0.1.1 · maintenance · verified Fri Apr 17

streamlit-ace is a Streamlit component that embeds the Ace code editor, allowing users to interact with code snippets directly within their Streamlit applications. The library is currently at version 0.1.1, with its last commit in late 2021, indicating a slow release cadence and potential for compatibility considerations with recent Streamlit versions.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to embed the Ace editor in a Streamlit application, initialize it with content, and retrieve the user's edits. The `auto_update=True` parameter ensures that changes in the editor are immediately reflected in the Streamlit app.

import streamlit as st
from streamlit_ace import st_ace

st.set_page_config(layout="wide")
st.title("Streamlit Ace Editor Example")

initial_content = """import pandas as pd

def hello_world():
    print("Hello, Streamlit Ace!")

hello_world()
"""

content = st_ace(
    value=initial_content,
    language="python",
    theme="dracula",
    keybinding="vscode",
    height=200,
    font_size=14,
    tab_size=4,
    show_gutter=True,
    show_print_margin=True,
    wrap=False,
    auto_update=True, # Set to True to get immediate updates
    readonly=False,
    annotations=[{"row": 0, "column": 0, "text": "Welcome to Ace!", "type": "info"}]
)

st.subheader("Editor Content:")
st.code(content, language="python")

if st.button("Run Code (simulated)"):
    st.success("Code execution triggered with current content.")

view raw JSON →