Skip to content

Commit

Permalink
Improves the examples so they're fully runnable
Browse files Browse the repository at this point in the history
We still need to add READMEs
  • Loading branch information
elijahbenizzy committed Feb 9, 2024
1 parent 628fcea commit a18d028
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
12 changes: 8 additions & 4 deletions burr/integrations/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ def prior_actions(self) -> List[str]:
return out

@property
def next_action(self) -> str:
def next_action(self) -> Optional[str]:
if self.display_index < len(self.history) - 1:
return self.history[self.display_index + 1].action
if self.app.get_next_action() is None:
return None
return self.app.get_next_action().name # return the future one

@property
Expand Down Expand Up @@ -122,9 +124,11 @@ def lighten_color(color, amount=0.5):
lightened_color = colorsys.hls_to_rgb(c[0], 1 - amount * (1 - c[1]), c[2])
return mc.to_hex(lightened_color)

seen = {current_node}
digraph.node(current_node, fillcolor="darkgreen", style="rounded,filled", fontcolor="white")
digraph.node(next_node, fillcolor="blue", style="rounded,filled", fontcolor="white")
seen = {current_node, next_node}
if next_node is not None:
digraph.node(next_node, fillcolor="blue", style="rounded,filled", fontcolor="white")
seen.add(next_node)
base_color = "lightblue"
for i, node in enumerate(prior_nodes):
if node not in seen:
Expand Down Expand Up @@ -272,7 +276,7 @@ def stringify(i):
# TODO -- consider a callback here instead
app_state.display_index = current_node_index

with placeholder.container(height=800):
with placeholder.container(height=900):
state_machine_view, step_view, data_view = st.tabs(
["Application", "Action", "State/Results"]
)
Expand Down
22 changes: 17 additions & 5 deletions examples/counter/streamlit_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import counter
import application as counter
import streamlit as st

from burr.integrations.streamlit import (
Expand Down Expand Up @@ -36,16 +36,28 @@ def retrieve_state():

def main():
st.set_page_config(layout="wide")
st.title("Counting numbers with Burr")
app_state = retrieve_state() # retrieve first so we can use for the ret of the step
columns = st.columns(2)
with columns[0]:
sidebar = st.sidebar
with sidebar:
st.markdown(
"""
<style>
section[data-testid="stSidebar"] {
width: 400px !important; # Set the width to your desired value
}
</style>
""",
unsafe_allow_html=True,
)
st.title("Counting numbers with Burr")
st.write(
"This is a simple counter app. It counts to 10, then loops back to 0. You can reset it at any time. "
"While we know that this is easy to do with a simple loop + streamlit, it highlights the state that Burr manages."
"Use the slider to rewind/see what happened in the past, and the visualizations to understand how we navigate "
"through the state machine!"
)
app_state = retrieve_state() # retrieve first so we can use for the ret of the step
columns = st.columns(2)
with columns[0]:
counter_view(app_state)
with st.container(height=800):
md_lines = []
Expand Down

0 comments on commit a18d028

Please sign in to comment.