Skip to content

Commit 16e581f

Browse files
committed
Fix memo
1 parent 4f39005 commit 16e581f

File tree

3 files changed

+39
-45
lines changed

3 files changed

+39
-45
lines changed

frameworks/python/streamlit/README.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@ An example showing integration of [Streamlit](https://streamlit.io/) (Python) wi
44

55
It extends the Stock Peers example from the Streamlit app gallery: https://demo-stockpeers.streamlit.app/
66

7+
## Try it on your machine
8+
9+
1. Start a virtual environment and get the dependencies (requires [uv](https://github.com/astral-sh/uv)):
10+
11+
```sh
12+
$ uv venv
13+
14+
$ source .venv/bin/activate
15+
16+
$ uv sync
17+
```
18+
19+
2. Build the client bridge
20+
21+
```sh
22+
$ cd openfin_bridge_component/frontend
23+
24+
$ npm install
25+
26+
$ npm run build
27+
```
28+
29+
3. Start the app:
30+
31+
(From the root directory)
32+
33+
```sh
34+
$ streamlit run streamlit_app.py
35+
```
36+
737
## How it works
838

939
This project demonstrates a bidirectional communication bridge between a Python Streamlit application and the OpenFin platform using the FDC3 Interop API. The integration enables seamless data sharing between Streamlit and other OpenFin applications.
@@ -89,32 +119,3 @@ The `context.ts` helper module handles bidirectional mapping:
89119
- The OpenFin runtime is not a direct dependency but is expected to be running when the app is launched in an OpenFin container
90120
- The app gracefully handles cases where OpenFin is not available (e.g., when running in a standard browser)
91121

92-
## Try it on your machine
93-
94-
1. Start a virtual environment and get the dependencies (requires [uv](https://github.com/astral-sh/uv)):
95-
96-
```sh
97-
$ uv venv
98-
99-
$ source .venv/bin/activate
100-
101-
$ uv sync
102-
```
103-
104-
2. Build the client bridge
105-
106-
```sh
107-
$ cd openfin_bridge_component/frontend
108-
109-
$ npm install
110-
111-
$ npm run build
112-
```
113-
114-
3. Start the app:
115-
116-
(From the root directory)
117-
118-
```sh
119-
$ streamlit run streamlit_app.py
120-
```

frameworks/python/streamlit/openfin_bridge_component/frontend/src/main.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useRef } from "react"
1+
import React, { useEffect, useRef } from "react"
22
import { createRoot } from "react-dom/client"
33
import { Streamlit, withStreamlitConnection } from "streamlit-component-lib"
44
import { mapInbound, mapOutbound, hashContext } from './helpers/context';
@@ -9,16 +9,10 @@ type Args = {
99
data?: any
1010
}
1111

12-
function useStableJson<T>(value: T): string {
13-
// Recompute JSON only when necessary to keep useEffect deps stable
14-
return useMemo(() => JSON.stringify(value ?? null), [value])
15-
}
16-
1712
const SUPPRESSION_WINDOW_MS = 900 // ignore self-echo within this window
1813

1914
function Bridge({ args }: { args: Args }) {
2015
const groupRef = useRef<any>(null)
21-
const argsJson = useStableJson(args)
2216
const lastOutboundHashRef = useRef<string | null>(null)
2317
const lastOutboundAtRef = useRef<number>(0)
2418

@@ -84,8 +78,7 @@ function Bridge({ args }: { args: Args }) {
8478

8579
// Outbound broadcast when args change
8680
useEffect(() => {
87-
const parsed: Args = JSON.parse(argsJson)
88-
const ctx = mapOutbound(parsed?.eventType, parsed?.data)
81+
const ctx = mapOutbound(args?.eventType, args?.data)
8982
if (!ctx || !groupRef.current) return
9083
try {
9184
// Record hash & timestamp for self-echo suppression on next inbound
@@ -95,7 +88,7 @@ function Bridge({ args }: { args: Args }) {
9588
groupRef.current
9689
.setContext(ctx)
9790
.catch((e: any) => console.error("[OpenFinBridge] setContext error", e))
98-
}, [argsJson])
91+
}, [JSON.stringify(args)])
9992

10093
return null
10194
}

frameworks/react/workspace/src/views/monitor.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ export function Monitor() {
168168
<table style={{ width: "100%", borderCollapse: "separate", borderSpacing: 0 }}>
169169
<thead>
170170
<tr style={{ background: "#f5f7fa" }}>
171-
<th style={{ textAlign: "left", padding: "8px 12px", borderBottom: "1px solid #e5e7eb" }}>Ticker</th>
172-
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb" }}>Price</th>
173-
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb" }}>Change</th>
174-
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb" }}>%</th>
175-
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb" }}>Volume</th>
176-
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb" }}>Day Range</th>
171+
<th style={{ textAlign: "left", padding: "8px 12px", borderBottom: "1px solid #e5e7eb", color: "#888" }}>Ticker</th>
172+
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb", color: "#888" }}>Price</th>
173+
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb", color: "#888" }}>Change</th>
174+
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb", color: "#888" }}>%</th>
175+
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb", color: "#888" }}>Volume</th>
176+
<th style={{ textAlign: "right", padding: "8px 12px", borderBottom: "1px solid #e5e7eb", color: "#888" }}>Day Range</th>
177177
</tr>
178178
</thead>
179179
<tbody>

0 commit comments

Comments
 (0)