Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Node.js server for offline export of Plotly graphs

License

NotificationsYou must be signed in to change notification settings

ge-tracker/plotly-node-export-server

 
 

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.

Requirements

This application needs one prerequisite:

  • Node.js 18 or later (preferably the latest LTS version)

Installation of Node.js

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.)

Initial setup: install Node.js dependency packages

The application requires a package forjsdom. To install that, type

npm install

in the directoryexport-server/. You only need to do this once. The packagesare then cached in thenode_modules/ directory for future use.

Start the application

You can simply start the application via

npm start

which 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 start

The 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 start

IfHOST is not set, thenlocalhost will be used as hostname.

Usage

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:

Generated image example

The generated image will be contained in the response message body.

Adjusting the width and height of the generated image

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: 500

Using the same JSON as above, the created image will now be slightly larger andlook like this:

Custom size image example

Troubleshooting

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.

Version history

A version history is available inchangelog.md.

Copyright and Licensing

Copyright 2018, 2020, 2021, 2022, 2023 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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript88.3%
  • Dockerfile6.0%
  • Shell5.7%

[8]ページ先頭

©2009-2025 Movatter.jp