- Notifications
You must be signed in to change notification settings - Fork3
Node.js server for offline export of Plotly graphs
License
striezel/plotly-node-export-server
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This repository contains a Node.js application that starts a server which canrenderPlotly.js graphs to SVG imageswithout sending the data to the servers of Plotly. That means all plot datastays on this local server and is NOT sent over the net. If you value theprivacy of your data, this might be a better option for you than using the APIon the Plotly servers.
This application needs one prerequisite:
- Node.js 20 or later (preferably the latest LTS version)
The installation of Node.js is covered in aseparate document.
(If you prefer a setup within a Docker container over a native installation,then please take a look atSetup with Docker.)
The application requires a package forjsdom. To install that, type
npm installin the directoryexport-server/. You only need to do this once. The packagesare then cached in thenode_modules/ directory for future use.
You can simply start the application via
npm startwhich fires up the Node.js application. The server will then listen onhttp://localhost:3000/ for incoming connections.
If you want the server to listen on a different port, then you can set theenvironment variablePORT accordingly. On Linux-like systems you can do
export PORT=4000npm startThe equivalent on Windows command prompt would be
SETPORT=4000npmstart
In these cases the server will bind to port 4000 instead of the default port3000.
The hostname can be changed, too, by setting theHOST environment variable inthe same manner, e. g.:
export HOST=0.0.0.0npm startIfHOST is not set, thenlocalhost will be used as hostname.
To generate a SVG file of a Plotly plot, just send an HTTP POST request to therunning Node.js server onhttp://localhost:3000/ containing the data for theplot as JSON in its body.
For example, POSTing the following JSON code to the server
{ "x": ["2013-10-04 22:23:00", "2013-11-04 22:23:00", "2013-12-04 22:23:00"], "y": [1, 3, 6], "type": "scatter"}will generate a SVG image that looks like this:
The generated image will be contained in the response message body.
The generated SVG image has a width of 700 pixels and a height of 400 pixels bydefault. If no size is specified, then the image will be of that default size.However, this may not always be suitable for your needs.
To change the size, add the HTTP headersX-Image-Width and / orX-Image-Height to the request. Acceptable values are integers only, the valueswill be interpreted as pixels, not centimetres, inches or other. For example, ifyou want the image to be 750 x 500 pixels, then set the HTTP headers
X-Image-Width: 750X-Image-Height: 500Using the same JSON as above, the created image will now be slightly larger andlook like this:
Layout information can be added by specifyingdata andlayout as separatemembers of thePOSTed JSON. For example, the following JSON uses thelayout.title.text member to set a title for the generated plot:
{ "data": [ { "x": ["2013-10-04 22:23:00", "2013-11-04 22:23:00", "2013-12-04 22:23:00"], "y": [1, 3, 6], "type": "scatter" } ], "layout": { "title": { "text": "Example title" } }}The generated image may look like this:
If you encounter problems while trying to generate a plot image, then pleasetake a look atthe FAQ. Some commonerrors and possible solutions are listed there.
A version history is available inchangelog.md.
Copyright 2018, 2020, 2021, 2022, 2023, 2024, 2025 Dirk Stolle
This program is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.
This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.
You should have received a copy of the GNU General Public Licensealong with this program. If not, seehttp://www.gnu.org/licenses/.
About
Node.js server for offline export of Plotly graphs
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.