11 Server-side visualization

 

This chapter covers

  • Rendering charts and visualizations with Node.js
  • Building reusable functions for rendering charts that we can use when doing exploratory data analysis
  • Using a headless browser to capture web pages to PNG image files and PDF documents
  • Taking web scraping to the next level with a headless browser

When we’re doing exploratory coding (chapter 5) or data analysis (chapter 9), we want to render charts and visualizations to explore and understand our data. In chapter 10, we learned how to create web-based interactive visualizations for the browser. That’s a normal and common way to create visualizations in JavaScript. Browser-based visualization techniques are well known and well understood, and you can easily find help on the internet.

How about we take the browser out of the equation? What if we want to render our charts and visualization on the server directly from Node.js? Well, we can do that, but unlike browser-based visualization, this isn’t a common use case, and it can be difficult to find the help you need online.

First, though, you might wonder why it’s useful to render charts on the server side? It’s convenient for us to render charts directly from Node.js while doing exploratory data analysis (that’s what we were doing in chapter 9). This approach to data analysis is common in Python, and it would be nice if we could replicate it in Node.js.

11.1 Expanding your toolkit

11.2 Getting the code and data

11.3 The headless browser

11.4 Using Nightmare for server-side visualization

11.4.1 Why Nightmare?

11.4.2 Nightmare and Electron

11.4.3 Our process: capturing visualizations with Nightmare

11.4.4 Prepare a visualization to render

11.4.5 Starting the web server

11.4.6 Procedurally start and stop the web server

11.4.7 Rendering the web page to an image

11.4.8 Before we move on . . .

11.4.9 Capturing the full visualization

Feeding the chart with data

Multipage reports

Debugging code in the headless browser

Making it work on a Linux server

11.5 You can do much more with a headless browser

11.5.1 Web scraping

11.5.2 Other uses

Summary