Skip to content

Commit 0fe07a6

Browse files
Release 1.51.0 (#1365)
* Feature/custom components v2 (#1364) * Fix Tailwind example CSS * Custom components with Typescript * Custom component API reference * st.space * streamlit run * Configuration options * LIght and dark theming * Release notes * Smart quotes * What's new * Cheat sheet * Bump apps to latest * Add cleanup function and npm refcards * Review edits
1 parent 774f6da commit 0fe07a6

File tree

53 files changed

+13390
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+13390
-155
lines changed

components/blocks/autofunction.js

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,19 @@ const Autofunction = ({
159159
let headerTitle;
160160
let body;
161161
let isClass;
162+
let isInterface;
162163
let isAttributeDict;
164+
let isTypeAlias;
163165
let methods = [];
164166
let properties = [];
165167

166168
if (streamlitFunction in docstrings || oldStreamlitFunction in docstrings) {
167169
functionObject =
168170
docstrings[streamlitFunction] ?? docstrings[oldStreamlitFunction];
169-
isClass = functionObject.is_class;
171+
isClass = functionObject.is_class ?? false;
172+
isInterface = functionObject.is_interface ?? false;
170173
isAttributeDict = functionObject.is_attribute_dict ?? false;
174+
isTypeAlias = functionObject.type === "type_alias";
171175
if (
172176
functionObject.description !== undefined &&
173177
functionObject.description
@@ -222,9 +226,12 @@ const Autofunction = ({
222226
if (hideHeader !== undefined && hideHeader) {
223227
header = "";
224228
} else {
225-
const name = functionObject.signature
226-
? `${functionObject.signature}`.split("(")[0].replace("streamlit", "st")
227-
: "";
229+
let name = "";
230+
if (isInterface || isTypeAlias) {
231+
name = functionObject.name;
232+
} else if (functionObject.signature) {
233+
name = functionObject.signature.split("(")[0].replace("streamlit", "st");
234+
}
228235
headerTitle = isAttributeDict ? (
229236
<H3 className={styles.Title}>
230237
<a
@@ -351,10 +358,10 @@ const Autofunction = ({
351358
// When "Parameters" are included in a class docstring, they are actually
352359
// "Properties." Using "Properties" in the docstring does not result in
353360
// individually parsed properties; using "Parameters" is a workaround.
354-
if (isClass) {
355-
propertiesRows.push(row);
356-
} else {
361+
if (!isClass || isInterface) {
357362
args.push(row);
363+
} else {
364+
propertiesRows.push(row);
358365
}
359366
}
360367

@@ -364,7 +371,9 @@ const Autofunction = ({
364371
const row = {};
365372
const method = methods[index];
366373
const slicedSlug = slug.slice().join("/");
367-
const hrefName = `${functionObject.name}.${method.name}`
374+
const hrefName = (
375+
isTypeAlias ? method.name : `${functionObject.name}.${method.name}`
376+
)
368377
.toLowerCase()
369378
.replace("streamlit", "st")
370379
.replace(/[.,\/#!$%\^&\*;:{}=\-`~()]/g, "");
@@ -454,6 +463,16 @@ const Autofunction = ({
454463
returns.push(row);
455464
}
456465

466+
const getArgsTitle = () => {
467+
if (isTypeAlias && !isInterface) {
468+
return "Properties"; // For TypeScript type aliases that aren't function interfaces
469+
}
470+
if (isTypeAlias) {
471+
return "Arguments"; // For TypeScript function interfaces
472+
}
473+
return "Parameters"; // For Python functions
474+
};
475+
457476
body = (
458477
<Table
459478
head={
@@ -462,7 +481,11 @@ const Autofunction = ({
462481
: {
463482
title: (
464483
<>
465-
{isClass ? "Class description" : "Function signature"}
484+
{isTypeAlias
485+
? "(TypeScript) Type alias description"
486+
: isClass
487+
? "Class description"
488+
: "Function signature"}
466489
<a
467490
className={styles.Title.a}
468491
href={functionObject.source}
@@ -481,12 +504,22 @@ const Autofunction = ({
481504
content: `<p class='code'> ${functionObject.signature}</p> `,
482505
}
483506
}
484-
body={args.length ? { title: "Parameters" } : null}
507+
body={
508+
args.length
509+
? {
510+
title: getArgsTitle(),
511+
}
512+
: null
513+
}
485514
bodyRows={args.length ? args : null}
486515
foot={[
487-
methods.length ? { title: "Methods" } : null,
516+
methods.length
517+
? { title: isTypeAlias ? "Functions" : "Methods" }
518+
: null,
488519
returns.length ? { title: "Returns" } : null,
489-
propertiesRows.length ? { title: "Attributes" } : null,
520+
propertiesRows.length
521+
? { title: isTypeAlias ? "Properties" : "Attributes" }
522+
: null,
490523
].filter((section) => section !== null)}
491524
footRows={[
492525
methods.length ? methodRows : null,

content/develop/api-reference/_index.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,19 @@ st.sidebar.write("This lives in the sidebar")
15821582
st.sidebar.button("Click me!")
15831583
```
15841584

1585+
</RefCard>
1586+
<RefCard href="/develop/api-reference/layout/st.space">
1587+
1588+
<Image pure alt="screenshot" src="/images/api/space.jpg" />
1589+
1590+
<h4>Space</h4>
1591+
1592+
Add vertical or horizontal space.
1593+
1594+
```python
1595+
st.space("small")
1596+
```
1597+
15851598
</RefCard>
15861599
<RefCard href="/develop/api-reference/layout/st.tabs">
15871600

@@ -2424,6 +2437,106 @@ st.write(user_info)
24242437

24252438
<br />
24262439

2440+
#### V2 custom components
2441+
2442+
<TileContainer>
2443+
2444+
<RefCard href="/develop/api-reference/custom-components/st.components.v2.component">
2445+
2446+
<h4>Register</h4>
2447+
2448+
Register a custom component.
2449+
2450+
```python
2451+
my_component = st.components.v2.component(
2452+
html=HTML,
2453+
js=JS
2454+
)
2455+
my_component()
2456+
```
2457+
2458+
</RefCard>
2459+
2460+
<RefCard href="/develop/api-reference/custom-components/st.components.v2.types.bidicomponentcallable">
2461+
2462+
<h4>Mount</h4>
2463+
2464+
Mount a custom component.
2465+
2466+
```python
2467+
my_component = st.components.v2.component(
2468+
html=HTML,
2469+
js=JS
2470+
)
2471+
my_component()
2472+
```
2473+
2474+
</RefCard>
2475+
2476+
<RefCard href="/develop/api-reference/custom-components/component-v2-lib">
2477+
2478+
<h4>npm support code</h4>
2479+
2480+
Support code published through npm.
2481+
2482+
```bash
2483+
npm i @streamlit/component-v2-lib
2484+
```
2485+
2486+
</RefCard>
2487+
2488+
<RefCard href="/develop/api-reference/custom-components/component-v2-lib-component">
2489+
2490+
<h4>Component</h4>
2491+
2492+
Type alias for the component function.
2493+
2494+
```typescript
2495+
import { Component } from "@streamlit/component-v2-lib";
2496+
```
2497+
2498+
</RefCard>
2499+
2500+
<RefCard href="/develop/api-reference/custom-components/component-v2-lib-componentargs">
2501+
2502+
<h4>ComponentArgs</h4>
2503+
2504+
Type alias for the component arguments.
2505+
2506+
```typescript
2507+
import { ComponentArgs } from "@streamlit/component-v2-lib";
2508+
```
2509+
2510+
</RefCard>
2511+
2512+
<RefCard href="/develop/api-reference/custom-components/component-v2-lib-componentstate">
2513+
2514+
<h4>ComponentState</h4>
2515+
2516+
Type alias for the component state.
2517+
2518+
```typescript
2519+
import { ComponentState } from "@streamlit/component-v2-lib";
2520+
```
2521+
2522+
</RefCard>
2523+
2524+
<RefCard href="/develop/api-reference/custom-components/component-v2-lib-optionalcomponentcleanupfunction" size="two-third">
2525+
2526+
<h4>OptionalComponentCleanupFunction</h4>
2527+
2528+
Type alias for the component cleanup function.
2529+
2530+
```typescript
2531+
import { OptionalComponentCleanupFunction } from "@streamlit/component-v2-lib";
2532+
```
2533+
2534+
</RefCard>
2535+
2536+
</TileContainer>
2537+
2538+
#### V1 custom components
2539+
24272540
<TileContainer>
24282541

24292542
<RefCard href="/develop/api-reference/custom-components/st.components.v1.declare_component">

content/develop/api-reference/command-line/run.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ This command starts your Streamlit app.
1212
### Syntax
1313

1414
```
15-
streamlit run <entrypoint file> [-- config options] [script args]
15+
streamlit run [<entrypoint file or directory>] [-- config options] [script args]
1616
```
1717

1818
### Arguments
1919

20-
`<entrypoint file>`: The path to your entrypoint file for your Streamlit app. In a multipage app with `st.navigation`, your entrypoint file acts as a router between your pages. Otherwise, your entrypoint file is your app's homepage.
20+
`<entrypoint file or directory>` (optional): The path to your entrypoint file or directory for your Streamlit app.
21+
22+
- **If not provided**: Streamlit will try to run `streamlit_app.py` from the current working directory.
23+
- **If a directory path is provided**: Streamlit will try to run `streamlit_app.py` in the specified directory.
24+
- **If a file path is provided**: Streamlit will run the specified file.
25+
26+
In a multipage app with `st.navigation`, your entrypoint file acts as a router between your pages. Otherwise, your entrypoint file is your app's homepage.
2127

2228
### Options
2329

@@ -31,44 +37,62 @@ For a complete list of configuration options, see [`config.toml`](/develop/api-r
3137

3238
### Script arguments
3339

34-
If you need to pass arguments directly to your script, you can pass them as positional arguments. If you use `sys.argv` to read your arguments, `sys.arfgv` returns a list of all arugments and does _not_ include any configuration options. Python interprets all arguments as strings.
40+
If you need to pass arguments directly to your script, you can pass them as positional arguments. If you use `sys.argv` to read your arguments, `sys.argv` returns a list of all arguments and does _not_ include any configuration options. Python interprets all arguments as strings.
3541

36-
- `sys.argv[0]` returns the provided path to your entrypoint file (`<entrypoint file>`).
42+
- `sys.argv[0]` returns the the path to your entrypoint file, even if you did not explicitly provide it.
3743
- `sys.argv[1:]` returns a list of arguments in order and does not include any configuration options.
3844

3945
### Examples
4046

41-
- If your app is in your working directory, run it as follows:
47+
- If your app is named `streamlit_app.py` in your working directory, you can run it with the following command:
48+
49+
```
50+
streamlit run
51+
```
52+
53+
- If your app has a different name and is in your working directory, run it like the following command:
4254

4355
```
4456
streamlit run your_app.py
4557
```
4658

47-
- If your app is in a subdirectory, run it as follows:
59+
- If your app is named `streamlit_app.py` in a subdirectory, you can run it like the following command:
60+
61+
```
62+
streamlit run your_subdirectory
63+
```
64+
65+
- If your app has a different name and is in a subdirectory, run it like the following command:
4866

4967
```
5068
streamlit run your_subdirectory/your_app.py
5169
```
5270

53-
- If your app is saved in a public GitHub repo or gist, run it as follows:
71+
- If your app is saved in a public GitHub repo or gist, run it like the following command:
5472

5573
```
5674
streamlit run https://raw.githubusercontent.com/streamlit/demo-uber-nyc-pickups/master/streamlit_app.py
5775
```
5876

59-
- If you need to set one or more configuration options, run it as follows:
77+
- If you need to set one or more configuration options, run it like the following command:
6078

6179
```
6280
streamlit run your_app.py --client.showErrorDetails=False --theme.primaryColor=blue
6381
```
6482

65-
- If you need to pass an argument to your script, run it as follows:
83+
Or if using the default `streamlit_app.py`:
84+
85+
```
86+
streamlit run --client.showErrorDetails=False --theme.primaryColor=blue
87+
```
88+
89+
- If you need to pass an argument to your script, run it like the following command:
6690

6791
```
6892
streamlit run your_app.py "my list" of arguments
6993
```
7094

71-
Within your script, the following statement will be true:
95+
Within your script, the following statements will be true:
7296

7397
```
7498
sys.argv[0] == "your_app.py"

0 commit comments

Comments
 (0)