DreamLake
Browse docs

Build a custom preview

Use the views when your application already has parsed data or needs its own layout. A CSV result goes to TableView; an object goes to JsonTreeView; media views take playable URLs.

The example below combines a loader, table and persistent header. Use FilePreview when its built-in layout is sufficient.

Usage

Keep the header visible while CSV data loads:

CustomCsvPreview.tsxtsx
import {
  PreviewHeader,
  TableView,
  StatusView,
  loadCsv,
  useLoader,
} from "@dreamlake/viz";
import type { FileMetadata } from "@dreamlake/viz";

export function CustomCsvPreview({
  file,
  src,
}: {
  file: FileMetadata;
  src: string;
}) {
  const { data, error, loading } = useLoader(
    (signal) => loadCsv(src, { size: file.size, signal }),
    [src, file.size],
  );
  return (
    <div className="flex flex-col h-full">
      <PreviewHeader {...file} />
      {loading ? (
        <StatusView kind="loading" />
      ) : error ? (
        <StatusView kind="error" message={error.message} />
      ) : data ? (
        <TableView
          cols={data.header.map((name) => ({ name }))}
          rows={data.rows}
          totalRows={data.totalRows}
          truncated={data.truncated}
        />
      ) : null}
    </div>
  );
}

Choose a view from the data you already have:

DataView
Columns and rowsTableView
Ordered metadata pairsKeyValueView
One JSON valueJsonTreeView
A list of JSON recordsJsonlView
Image URLImageView
Video URLVideoView
Audio URLAudioView
TextTextView
Loading, error or another empty stateStatusView

Header & sub-bar

PreviewHeader

Shows the filename, parent directory and supplied metadata. size is in bytes; a missing parent directory displays as /.

datasets/2026-05/runs/
trajectories.parquet
4.6 MB2026-05-09 14:22
Code PreviewHeaderSpec.tsx

PreviewSubBar

Use the left slot for a summary and the right for actions or status, such as row count and truncation, or line count and Save. Both accept React content.

12 cols · 5,000 rows●showing first 100 rows
Code PreviewSubBarSpec.tsx

Tabular data

TableView

Pass columns and rows in matching order. Optional types appear below column names. Values render as supplied; the view does not parse or sort them.

5 cols · 5,000 rows●showing first 7 rows
#
idint64
episodestring
stepint32
rewardfloat32
donebool
1
1
ep-0001
0
0
false
2
2
ep-0001
1
0.12
false
3
3
ep-0001
2
0.34
false
4
4
ep-0001
3
0.87
true
5
5
ep-0002
0
0
false
6
6
ep-0002
1
null
false
7
7
ep-0002
2
0.51
true
Code TableViewSpec.tsx

For a sample, set truncated and, if known, totalRows. shownRows changes only the summary label: every supplied row renders. Slice or page rows first.

Replace summaries with subInfoLeft and subInfoRight, or hide them with hideSubBar.

KeyValueView

Pass string pairs for metadata such as array shape, dtype or recording duration. The view preserves their order.

formatApache Parquet v2.9
compressionZSTD (level 3)
rows5,000
row groups4
created bypyarrow 15.0.2
schema shaa31b…f902
Code KeyValueViewSpec.tsx

JSON & JSONL

JsonTreeView

Expand object and array labels to inspect a parsed value. defaultOpenDepth={1} opens the root; larger values open more levels.

▾{
"run": "rl/2026-05-09/seed-42"
▾"config": {
"algo": "ppo"
"horizon": 2048
"gamma": 0.995
▸"optimizer": { 3 keys }
▸"env": { 3 keys }
}
▾"metrics": {
"reward_mean": 0.873
"reward_std": 0.214
"success_rate": 0.91
"episodes": 1280
}
▾"tags": [
"rl"
"panda"
"reach"
"curriculum"
]
"finished": true
"note": null
}
Code JsonTreeViewSpec.tsx

JsonlView

Pass the records returned by loadJsonl to display numbered lines.

1
2
3
4
5
6
{"t": 0, "kind": "reset", "env": 0, "obs_hash": "a3f1"}
{"t": 0.02, "kind": "step", "env": 0, "action": [0.12, -0.03, 0.04], "r": 0, "done": false}
{"t": 0.04, "kind": "step", "env": 0, "action": [0.18, 0.01, 0.05], "r": 0.12, "done": false}
{"t": 0.06, "kind": "step", "env": 0, "action": [0.21, -0.02, 0.07], "r": 0.34, "done": false}
{"t": 0.08, "kind": "step", "env": 0, "action": [0.1, 0.04, 0.02], "r": 0.87, "done": true}
{"t": 0.1, "kind": "reset", "env": 0, "obs_hash": "c0e7"}
Code JsonlViewSpec.tsx

Long records are truncated visually. Use JsonTreeView for full-record inspection.

Media

ImageView

Fits the image while preserving aspect ratio. Supply alt text; onLoad reports natural resolution as W×H.

Sample gradient
resolution · —
Code ImageViewSpec.tsx

VideoView

Uses native video controls. onLoadedMetadata reports seconds and W×H resolution. Playback depends on browser codec support; partial seeking reads depend on server Range support.

metadata · —
Code VideoViewSpec.tsx

Handle VideoErrorInfo through onError. Loading without metadata or an error shows an advisory after 15 seconds; change stallMs or set it to 0 to disable the advisory. See error demos.

AudioView

Uses native audio controls and reports duration in seconds through its metadata callback.

tsx
import { AudioView } from "@dreamlake/viz";

<AudioView
  src="/data/recording.wav"
  onLoadedMetadata={({ duration }) => {
    console.log(duration);
  }}
/>;

Text

TextView shows line-numbered text. onSave enables Edit; without it the view is read-only. ext labels the format without syntax highlighting or Markdown rendering.

8 lines · MD
1
2
3
4
5
6
7
8
# notes.md
- Verify the value-function head still trains on the new env.
- Re-run sweep at gamma in {0.99, 0.995, 0.999}.
- File regressions land in the parquet under datasets/2026-05/.

> The reward shaping change is responsible for the ~7% bump on
> success-rate. Roll forward.
Code TextViewSpec.tsx

Cmd/Ctrl-S saves; Escape discards edits. Resolve onSave after persistence and update the parent text value. Reject the promise to display an inline error.

A new text prop replaces unsaved edits and exits editing. Apply refreshes only when the application intends that replacement.

Status states

Render a status in the content area while the preview is unavailable:

Select a file to preview.
Code StatusViewSpec.tsx
kindWhen to use itRelevant props
emptyNo file is selected.—
loadingFetching or parsing.label describes the operation.
errorLoading or parsing failed.message, optional label and hint.
too-largeThe file exceeds your preview limit.sizeBytes, capBytes, optional hint.
unsupportedNo preview handles the format.ext names the extension.

Use hint for recovery instructions or a download link. Keep the same container size while switching between status and content.

Props reference

PreviewHeader props

PropTypeDefaultMeaning
namestringrequiredFilename.
extstringomittedExtension used for the file icon.
pathstringomittedFull path; its parent directory appears above the filename.
sizenumberomittedByte size.
modifiedDate | stringomittedDates are formatted as YYYY-MM-DD HH:mm; strings display as supplied.

PreviewSubBar props

PropTypeDefaultMeaning
leftReactNoderequiredSummary or other content on the left.
rightReactNoderequiredActions or status on the right; pass null if unused.

TableView props

PropTypeDefaultMeaning
colsTableColumn[]required{ name, type? } definitions in display order.
rowsunknown[][]requiredRows with values in column order. All supplied rows render.
totalRowsnumber | nullshown countTotal row count when known.
shownRowsnumberrows.lengthCount used in summary labels; does not slice rows.
truncatedbooleanfalseShows the partial-result notice.
subInfoLeftReactNodecountsReplaces the left summary.
subInfoRightReactNodetruncation noticeReplaces the right summary.
hideSubBarbooleanfalseOmits the summary bar.

KeyValueView props

PropTypeDefaultMeaning
itemsArray<[string, string]>requiredKey/value pairs in display order.

JsonTreeView props

PropTypeDefaultMeaning
valueunknownrequiredParsed JSON object, array or scalar.
defaultOpenDepthnumber2Levels initially open. 0 starts collapsed; Infinity opens all levels.

JsonlView props

PropTypeDefaultMeaning
recordsunknown[]requiredParsed records, displayed one per line.

ImageView props

PropTypeDefaultMeaning
srcstringrequiredImage URL.
altstring''Alternative text; supply a useful description.
onLoad(resolution: string) => voidomittedReceives natural dimensions as W×H.

VideoView props

PropTypeDefaultMeaning
srcstringrequiredVideo URL.
extstringomittedExtension included in error messages.
onLoadedMetadata(info: { duration: number; resolution: string }) => voidomittedReceives seconds and W×H dimensions. Zero-sized video calls onError instead.
onError(info: VideoErrorInfo) => voidomittedReceives { kind, code, title, message, hint } for a failure.
stallMsnumber15000Delay before the loading advisory; 0 disables it.

AudioView props

PropTypeDefaultMeaning
srcstringrequiredAudio URL.
onLoadedMetadata(info: { duration: number }) => voidomittedReceives duration in seconds.

TextView props

PropTypeDefaultMeaning
textstringrequiredText content. Changes replace local edits.
extstringomittedFormat label.
onSave(text: string) => Promise<void>omittedEnables editing. Resolve after saving; reject to display an error.

StatusView props

PropTypeDefaultMeaning
kind'empty' | 'loading' | 'error' | 'too-large' | 'unsupported'requiredState to display.
labelstringstate-specificLoading caption or error headline.
messagestring'Preview failed'Error detail.
extstringomittedExtension in the unsupported-format message.
sizeBytesnumber0Actual file size for too-large.
capBytesnumber0Preview limit for too-large.
hintReactNodeomittedAdditional error help, or replacement size-limit explanation.