httpgd
Version:
R httpgd GraphicsDevice API and connection handler
45 lines (28 loc) • 1.19 kB
Markdown
API and connection handler to connect with [R httpgd servers](https://github.com/nx10/httpgd).
- Simplify `httpgd` server access from JavaScript
- Full TypeScript type definitions
- Automatic WebSocket connection with polling fallback and reconnection
Minimal example how to listen for server side changes:
```JavaScript
import { Httpgd } from 'httpgd';
const httpgd = new Httpgd('127.0.0.1:1234', 'mytoken', true);
httpgd.onPlotsChanged((newState) => console.log(newState));
httpgd.connect();
// httpgd.removePlot(...)
// httpgd.getPlotURL(...)
```
Advanced usage example: The client included in the [httpgd R package](https://github.com/nx10/httpgd).
In applications where there is no need to continuously listen for server side changes, `httpgd` APIs can also be called directly using the `api` module.
Example:
```JavaScript
import { url_plot } from 'httpgd/lib/api';
const url = url_plot({ host: '127.0.0.1:1234' }, { id: 'myPlotId' });
document.getElementsByTagName('img')[0].src = url;
```
MIT