Saving images with the plotly module
goal
Using Python3's Plotly module, it implements the reading of database data, then forms a Table table and sends it to the pinned group at regular intervals via the pinned bot.
difficulty
Plotly itself is displayed through the html page, the first to save the picture needs to install some other packages; through the countless articles on the Internet are wrong, get nearly two days to get the environment, had to lament, the following summary of their own into an article, fly on the handle.
move
1. Environment
CentOS Linux release 7.6.1810 (Core)
2. Python environment 1)Install pip and pip32)Installing Python 3
3. Basic library installation psutil
pip3 install psutil requests
4, the use of plotly module must be installed orca
wget /plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage chmod +x orca-1.2.1-x86_64.AppImage # Absolute path ln -s /root/orca-1.2.1-x86_64.AppImage /usr/bin/orca# See if the orca command displays correctly, if it reports a dependency package error, you can see the next step for some of the main dependencies orca --help
5. orca installs relevant system dependencies.
yum install fuse-libs-2.9.2-11.el7.x86_64
yum install gtk2-2.24.31-1.el7.x86_64
yum install desktop-file-utils
yum install Xvfb
yum install xdg-utils-1.1.0-0.17.20120809git.
Tips:
If you don't know what kind of dependencies to install, then use this command to get yum provides
yum provides .2 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: * extras: * updates: fuse-libs-2.9.2-11.el7.i686 : File System in Userspace (FUSE) libraries Repo : base Matched from: Provides : .2
6. Add Script
After orca executes without error, execute the script with the path to the file downloaded in step 4.
#!/bin/bash
xvfb-run -a /root/-x86_64.AppImage "$@"
7. Testing
import plotly.graph_objects as go import as pio fig = (data=[(header=dict(values=['A Scores', 'B Scores']), cells=dict(values=[[100, 90, 80, 90], [95, 85, 75, 95]])) ]) pio.write_image(fig, '')
After executing this script, you will find one in the current directory, which is the image we saved, and then you can send the image to the pinned group through the pinned alert script.
Use the shell to generate the form:
You can generate a fixed-format table file based on the makedown format, and then use a tool like typora to open it and copy it into an excel file.
This is the whole content of this article.