Embedded components
The embedded components are React components on npm: one JSX element puts a genome browser in your page. They are the same views the full app is built from, so a track config that works there works here.
React 19 or newer is the only peer dependency. For a page that isn't a React
app, a <script> bundle includes its own React; see
non-React hosts.
Choosing a package
| Goal | Package | Component |
|---|---|---|
| One linear genome view | @jbrowse/react-linear-genome-view2, examples | <LinearGenomeView> |
| One circular genome view (e.g. SV chord diagrams) | @jbrowse/react-circular-genome-view2, examples | <CircularGenomeView> |
| Complete app (multiple view types, synteny, etc) | @jbrowse/react-app2, examples | <JBrowse> |
| Make your own custom UI around the engine | createViewState + @jbrowse/display-ui, examples | — |
Each package's storybook is the reference: copy-pasteable React code, one page per task (setting up the view, navigating from your own code, running a worker, theming, plugins).
A tracks entry is a track config, and the shortest one is { trackId, uri }.
The type and adapter come from the file's extension, and assemblyNames from
the component's one assembly (see
the shortest track).
@jbrowse/react-app2 has a stylesheet to import:
import '@jbrowse/react-app2/styles.css'. It holds no rules today, and it is
where the package ships any CSS it comes to need.
The props are initial values, like an input's defaultValue. The engine is
built once on first render and later prop changes are ignored. To switch
assembly or plugins on a mounted component, give it a React key that changes
with them so React remounts it.
Embedded views versus the full app
Embedded views are for genome browsing inside an existing page. For a standalone
browser, run JBrowse Web. @jbrowse/react-app2 sits
between: the whole app as a React component.
| Single-view components (LGV, CGV) | @jbrowse/react-app2 | JBrowse Web | |
|---|---|---|---|
| View types | One only | All of them, plugins included | All of them, plugins included |
| Feature detail | Opens in a dialog | Opens in a drawer | Opens in a left/right oriented drawer |
| Sessions | No built-in saving or loading | Held in your app's state, yours to persist | Save, import, export, plus local autosave |
| URLs | The page owns the URL | The page owns the URL | Reads URL params like &loc= and &session= |
Sessions and track manipulation are left to the embedding application. For Python or R, jbrowse-anywidget and JBrowseR wrap the same views.
Non-React hosts
Every package also exports an imperative controller — createLinearGenomeView,
createCircularGenomeView, createApp — with no JSX and no React root for you
to manage. The Python anywidget, R htmlwidgets, and
plain <script> pages are built on these controllers. See the vanillajs rows in
bundler examples below for a working reference
implementation of each.
Driving it from your code
createViewState takes the view to open as view, written with the same fields
a config or a link uses (Config and session JSON): where it opens
and which tracks it shows, with any of the view's own settings beside them. An
embedded view shows the loading spinner while the assembly loads:
const state = createViewState({
assembly,
tracks,
view: {
loc: 'chr1:1,000-2,000',
tracks: ['genes'],
highlight: ['chr1:1,500-1,600'],
hideHeader: true,
},
})locationandhighlightare shorthands forview.locandview.highlight, and the only two that also apply over adefaultSessionor a restoredsession.viewis the default session's view, so it excludesdefaultSession(Embedding JBrowse).jbrowseHub: 'hg38'in place ofassemblyfetches that genome from genomes.jbrowse.org: its sequence, refName aliases, track catalog and gene-name search, soview: { loc: 'BRCA1' }works andtracksadds your own files beside the hosted ones. Any UCSC database name or GenArk accession resolves. It is fetched, so it goes touseCreateViewStateorcreateViewStateAsync; the imperativecreateLinearGenomeViewtakes the same name as itsassembly. The circular view takes a list,jbrowseHub: ['hg38', 'mm39'], for two genomes on one circle.localFiles, aname -> bytesmap, serves a host whose data lives in a process rather than at a URL: a notebook kernel, an R session, anywhere with no web server and no CORS.tracksthen refers to a registered name as if it were a URL. Register an index under its conventional sibling name (peaks.bed.gz+peaks.bed.gz.tbi) and only the bytes the view needs are read.menuBardraws the app-shapedFilemenu bar above the embedded linear view, with the two items an embed can honour (open track, open connection);disableAddTracksempties that menu and removes the track selector's add-track affordances. Both are off by default.heightsets the view's height; it supersedes the olderdrawerViewHeight, which only applied while a drawer was open.- The imperative controllers take callbacks in place of props:
onLocationChangefires with the visible region as the user pans or zooms,onFeatureSelectwith the clicked feature,onSessionChangewith the view's layout whenever it settles (for a host offering "save this view"), andonErrorwhen the build itself fails, since building is asynchronous and that throw cannot reach your own call.createApp'sonPluginsUpdatedfires when something changes the running plugin set, with what a rebuild needs to remount the app on the new set.
Bundler examples
| Package | Bundler | Demo | Source |
|---|---|---|---|
| @jbrowse/react-app2 | next.js | demo | source |
| @jbrowse/react-app2 | vite | demo | source |
| @jbrowse/react-app2 | rsbuild | demo | source |
| @jbrowse/react-app2 | vanillajs | demo | source |
| @jbrowse/react-linear-genome-view2 | vite | demo | source |
| @jbrowse/react-linear-genome-view2 | rsbuild | demo | source |
| @jbrowse/react-linear-genome-view2 | next.js | demo | source |
| @jbrowse/react-linear-genome-view2 | vanillajs | demo | source |
| @jbrowse/react-circular-genome-view2 | vanillajs | demo | source |
| @jbrowse/react-circular-genome-view2 | next.js | demo | source |
| @jbrowse/display-ui (build your own) | vite | demo | source |
See also
- Embedding JBrowse
- jbrowse-anywidget: Python equivalent
- JBrowseR: R/Shiny equivalent