Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ st.header(st.session_state['name'])

#### Logic nested in a button with a rerun

Although callbacks are often preferred to avoid extra reruns, our first 'John Doe'/'Jane Doe' example can be modified by adding [`st.experimental_rerun`](/library/api-reference/control-flow/st.experimental_rerun) instead. If you need to acces data in `st.session_state` before the button that modifies it, you can include `st.experimental_rerun` to rerun the script after the change has been committed. This means the script will rerun twice when a button is clicked.
Although callbacks are often preferred to avoid extra reruns, our first 'John Doe'/'Jane Doe' example can be modified by adding [`st.rerun`](/library/api-reference/control-flow/st.rerun) instead. If you need to acces data in `st.session_state` before the button that modifies it, you can include `st.rerun` to rerun the script after the change has been committed. This means the script will rerun twice when a button is clicked.

```python
import streamlit as st
Expand All @@ -220,11 +220,11 @@ st.header(st.session_state['name'])

if st.button('Jane'):
st.session_state['name'] = 'Jane Doe'
st.experimental_rerun()
st.rerun()

if st.button('John'):
st.session_state['name'] = 'John Doe'
st.experimental_rerun()
st.rerun()

st.header(st.session_state['name'])
```
Expand All @@ -247,7 +247,7 @@ st.text_input('Name', key='name')
if st.button('Clear name'):
st.session_state.name = ''
if st.button('Streamlit!'):
set_name('Streamlit')
st.session_state.name = ('Streamlit')
```

</Important>
Expand Down
16 changes: 8 additions & 8 deletions content/library/advanced-features/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ The purpose of a form is to override the default behavior of Streamlit which rer

1. The user changes a widget's value on the frontend.
2. The widget's value in `st.session_state` and in the Python backend (server) is updated.
3. The script rerun begins.
3. The script rerun begins.
4. If the widget has a callback, it is executed as a prefix to the page rerun.
5. When the updated widget's function is executed during the rerun, it outputs the new value.

Expand Down Expand Up @@ -188,7 +188,7 @@ with st.form('addition'):

<Cloud src="https://doc-forms-process2.streamlit.app/?embed=true" height="400"/>

### Use `st.experimental_rerun`
### Use `st.rerun`

If your process affects content above your form, another alternative is using an extra rerun. This can be less resource-efficient though, and may be less desirable that the above options.

Expand All @@ -213,15 +213,15 @@ with st.form('addition'):
# a second rerun when the form is submitted to update the value above.
st.session_state.sum = a + b
if submit:
st.experimental_rerun()
st.rerun()
```

<Cloud src="https://doc-forms-process3.streamlit.app/?embed=true" height="400"/>

## Limitations

* Every form must contain a `st.form_submit_button`.
* `st.button` and `st.download_button` cannot be added to a form.
* `st.form` cannot be embedded inside another `st.form`.
* Callback functions can only be assigned to `st.form_submit_button` within a form; no other widgets in a form can have a callback.
* Interdependent widgets within a form are unlikely to be particularly useful. If you pass `widget1`'s value into `widget2` when they are both inside a form, then `widget2` will only update when the form is submitted.
- Every form must contain a `st.form_submit_button`.
- `st.button` and `st.download_button` cannot be added to a form.
- `st.form` cannot be embedded inside another `st.form`.
- Callback functions can only be assigned to `st.form_submit_button` within a form; no other widgets in a form can have a callback.
- Interdependent widgets within a form are unlikely to be particularly useful. If you pass `widget1`'s value into `widget2` when they are both inside a form, then `widget2` will only update when the form is submitted.
61 changes: 42 additions & 19 deletions content/library/api-cheat-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ slug: /library/cheatsheet

# Cheat Sheet

This is a summary of the docs, as of [Streamlit v1.26.0](https://pypi.org/project/streamlit/1.26.0/).
This is a summary of the docs, as of [Streamlit v1.27.0](https://pypi.org/project/streamlit/1.27.0/).

<Masonry>

Expand Down Expand Up @@ -117,6 +117,28 @@ st.video(data)

<CodeTile>

#### Display charts

```python
st.area_chart(df)
st.bar_chart(df)
st.line_chart(df)
st.map(df)
st.scatter_chart(df)

st.altair_chart(chart)
st.bokeh_chart(fig)
st.graphviz_chart(fig)
st.plotly_chart(fig)
st.pydeck_chart(chart)
st.pyplot(fig)
st.vega_lite_chart(df)
```

</CodeTile>

<CodeTile>

#### Add widgets to sidebar

```python
Expand Down Expand Up @@ -176,7 +198,7 @@ st.video(data)
# Stop execution immediately:
st.stop()
# Rerun script immediately:
st.experimental_rerun()
st.rerun()

# Group multiple widgets:
>>> with st.form(key='my_form'):
Expand All @@ -192,24 +214,25 @@ st.experimental_rerun()
#### Display interactive widgets

```python
st.button('Click me')
st.data_editor('Edit data', data)
st.checkbox('I agree')
st.toggle('Enable')
st.radio('Pick one', ['cats', 'dogs'])
st.selectbox('Pick one', ['cats', 'dogs'])
st.multiselect('Buy', ['milk', 'apples', 'potatoes'])
st.slider('Pick a number', 0, 100)
st.select_slider('Pick a size', ['S', 'M', 'L'])
st.text_input('First name')
st.number_input('Pick a number', 0, 10)
st.text_area('Text to translate')
st.date_input('Your birthday')
st.time_input('Meeting time')
st.file_uploader('Upload a CSV')
st.download_button('Download file', data)
st.button("Click me")
st.download_button("Download file", data)
st.link_button("Go to gallery", url)
st.data_editor("Edit data", data)
st.checkbox("I agree")
st.toggle("Enable")
st.radio("Pick one", ["cats", "dogs"])
st.selectbox("Pick one", ["cats", "dogs"])
st.multiselect("Buy", ["milk", "apples", "potatoes"])
st.slider("Pick a number", 0, 100)
st.select_slider("Pick a size", ["S", "M", "L"])
st.text_input("First name")
st.number_input("Pick a number", 0, 10)
st.text_area("Text to translate")
st.date_input("Your birthday")
st.time_input("Meeting time")
st.file_uploader("Upload a CSV")
st.camera_input("Take a picture")
st.color_picker('Pick a color')
st.color_picker("Pick a color")

# Use widgets' returned values in variables:
>>> for i in range(int(st.number_input('Num:'))):
Expand Down
56 changes: 41 additions & 15 deletions content/library/api/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,7 @@ style_metric_cards()
## Chart elements

<TileContainer>
<RefCard href="/library/api-reference/charts/st.line_chart">
<Image pure alt="screenshot" src="/images/api/line_chart.jpg" />

#### Simple line charts

Display a line chart.

```python
st.line_chart(my_data_frame)
```

</RefCard>
<RefCard href="/library/api-reference/charts/st.area_chart">
<Image pure alt="screenshot" src="/images/api/area_chart.jpg" />

Expand All @@ -463,6 +452,30 @@ Display a bar chart.
st.bar_chart(my_data_frame)
```

</RefCard>
<RefCard href="/library/api-reference/charts/st.line_chart">
<Image pure alt="screenshot" src="/images/api/line_chart.jpg" />

#### Simple line charts

Display a line chart.

```python
st.line_chart(my_data_frame)
```

</RefCard>
<RefCard href="/library/api-reference/charts/st.scatter_chart">
<Image pure alt="screenshot" src="/images/api/scatter_chart.svg" />

#### Simple scatter charts

Display a line chart.

```python
st.scatter_chart(my_data_frame)
```

</RefCard>
<RefCard href="/library/api-reference/charts/st.map">
<Image pure alt="screenshot" src="/images/api/map.jpg" />
Expand Down Expand Up @@ -706,7 +719,7 @@ st.altair_chart(chart, use_container_width=True)
<TileContainer>
<RefCard href="/library/api-reference/widgets/st.button">

<Image pure alt="screenshot" src="/images/api/button.jpg" />
<Image pure alt="screenshot" src="/images/api/button.svg" />

#### Button

Expand All @@ -732,7 +745,7 @@ edited = st.experimental_data_editor(df, num_rows="dynamic")
</RefCard>
<RefCard href="/library/api-reference/widgets/st.download_button">

<Image pure alt="screenshot" src="/images/api/download_button.jpg" />
<Image pure alt="screenshot" src="/images/api/download_button.svg" />

#### Download button

Expand All @@ -742,6 +755,19 @@ Display a download button widget.
st.download_button("Download file", file)
```

</RefCard>
<RefCard href="/library/api-reference/widgets/st.link_button">

<Image pure alt="screenshot" src="/images/api/link_button.svg" />

#### Link button

Display a link button.

```python
st.link_button("Go to gallery", url)
```

</RefCard>
<RefCard href="/library/api-reference/widgets/st.checkbox">

Expand Down Expand Up @@ -1699,14 +1725,14 @@ st.stop()
```

</RefCard>
<RefCard href="/library/api-reference/control-flow/st.experimental_rerun">
<RefCard href="/library/api-reference/control-flow/st.rerun">

#### Rerun script

Rerun the script immediately.

```python
st.experimental_rerun()
st.rerun()
```

</RefCard>
Expand Down
36 changes: 24 additions & 12 deletions content/library/api/charts/charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ finally we also provide a few chart types that are "native" to Streamlit,
like `st.line_chart` and `st.area_chart`.

<TileContainer>
<RefCard href="/library/api-reference/charts/st.line_chart">
<Image pure alt="screenshot" src="/images/api/line_chart.jpg" />

#### Simple line charts

Display a line chart.

```python
st.line_chart(my_data_frame)
```

</RefCard>
<RefCard href="/library/api-reference/charts/st.area_chart">
<Image pure alt="screenshot" src="/images/api/area_chart.jpg" />

Expand All @@ -50,6 +38,30 @@ Display a bar chart.
st.bar_chart(my_data_frame)
```

</RefCard>
<RefCard href="/library/api-reference/charts/st.line_chart">
<Image pure alt="screenshot" src="/images/api/line_chart.jpg" />

#### Simple line charts

Display a line chart.

```python
st.line_chart(my_data_frame)
```

</RefCard>
<RefCard href="/library/api-reference/charts/st.scatter_chart">
<Image pure alt="screenshot" src="/images/api/scatter_chart.svg" />

#### Simple scatter charts

Display a line chart.

```python
st.scatter_chart(my_data_frame)
```

</RefCard>
<RefCard href="/library/api-reference/charts/st.map">
<Image pure alt="screenshot" src="/images/api/map.jpg" />
Expand Down
7 changes: 7 additions & 0 deletions content/library/api/charts/scatter_chart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: st.scatter_chart
slug: /library/api-reference/charts/st.scatter_chart
description: st.scatter_chart displays an scatter chart.
---

<Autofunction function="streamlit.scatter_chart" />
4 changes: 2 additions & 2 deletions content/library/api/control-flow/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ st.stop()

</RefCard>

<RefCard href="/library/api-reference/control-flow/st.experimental_rerun">
<RefCard href="/library/api-reference/control-flow/st.rerun">

#### Rerun script

Rerun the script immediately.

```python
st.experimental_rerun()
st.rerun()
```

</RefCard>
Expand Down
8 changes: 1 addition & 7 deletions content/library/api/control-flow/experimental_rerun.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,4 @@ slug: /library/api-reference/control-flow/st.experimental_rerun
description: st.experimental_rerun will rerun the script immediately.
---

<Important>

This is an experimental feature. Experimental features and their APIs may change or be removed at any time. To learn more, click [here](/library/advanced-features/prerelease#experimental-features).

</Important>

<Autofunction function="streamlit.experimental_rerun" />
<Autofunction function="streamlit.experimental_rerun" deprecated={true} deprecatedText="<code>st.experimental_rerun</code> was deprecated in version 1.27.0. Use <a href='/library/api-reference/control-flow/st.rerun'><code>st.rerun</code></a> instead."/>
Loading