Git Product home page Git Product logo

cov-spectrum-ppretty's Introduction

cov-spectrum-ppretty

An API to make pretty plots for cov-spectrum.org.

The canonical usage is as follows:

  • the CoV-Spectrum website sends a request to the save endpoint that contains configuration information and data to plot in JSON format
  • the API returns the full filepath to where it saved plot(s) of the data. Plot files are named with the sha-256 hash of the request.

The repository structure is modeled on https://github.com/sol-eng/plumbpkg.

Run the API in a docker container

Start docker engine, then run:

docker build -t ppretty .
docker run --rm -p 80:7090 ppretty

You should be able to access the API docs at http://127.0.0.1/__docs__/.

Run the API locally

# Load all the functions in the ppretty package
devtools::load_all()

# Run the API locally
run_app()

Test the API

# Load all the functions in the ppretty package
devtools::load_all()

# Run all tests
devtools::test()

Export functions and update NAMESPACE

The NAMESPACE file contains the functions that are exported from the package. All functions that are called from run_app_production.R (i.e., including endpoints.R) must be exported.

To export a function, it must be annotated with @export. Then, run devtools::document() to generate an updated NAMESPACE file.

Orienting in the code

The API endpoints are defined in inst/plumber/endpoints.R. There, you'll notice that the request data is first transformed, with known date column names standardized to "date". Then, the request config and data are piped into the high-level function make_plot.

The idea is that the request data gets passed to a plot type-specific function by make_plot. The plot type is specified in the request's config information. The specific plotting functions use common aesthetics, date scales, and colors that are defined in plot_helper_functions and plot_shared_elements.

If using the endpoint /save the plot will be saved in several formats in a sub-directory within ./plots (this is to avoid a single directory with too many files). The names of the sub-directories use the first four characters of the hash of request. The file name is the full hash. The endpoint will return the relative path to the generated plots without the file endings, e.g., 37/fc/37fc9c4fa9a218355b92a554227809b55b8568d3418ec927877641a0e9a1481f.

cov-spectrum-ppretty's People

Contributors

chaoran-chen avatar sarahnadeau avatar

Stargazers

 avatar

Watchers

 avatar  avatar

cov-spectrum-ppretty's Issues

Log scale

It would be great to support log scale. I suggest adding scale as an optional field to the config. The allowed values should be linear (which is the default) and log.

Don't recreate existing files

Current behavior:

The /save endpoint will generate and save new plots upon every call. If plots already exist for the same request/hash, the old files will be overwritten.

Desired behavior:

Before generating the plots, the /save endpoint should check the file system to see whether the plots already exist. If yes, it should just return the path.

Show week number

Current behavior:

image

Desired behavior:

For weekly bar plots, the labels on the x-axis should contain the week number. E.g., "26 Sep 2022 (Week XX)". This would make it clearer that the numbers are per week.

Configurable plot output directory

Current behavior:

The generated plots are stored by default to inst/plumber/plots. For users who use the Docker image or just call run_app(), there is no way to change the path as it is fixed in endpoints.R.

Desired behavior:

  1. run_app() should accept an optional argument to change the path to the base output directory.
  2. run_app_production.R should also accept an optional argument. I.e., we should be able to call Rscript inst/run_app_production.R my/safe/hoard.

Truncate long labels in the middle?

Current behavior:

Long variant names are truncated after a certain number of characters.

Example: [exactly-5-of: S:346, S:356, S:444, S:445, S:450, S:446, S:452, S:460, S:486, S:490, S:494, S:493Q,S:144-]& ! (S:346- | S:356- | S:444- | S:445- | S:450- | S:446- | S:452- | S:486- | S:490- | S:494-) & !nextstrainClade:21K & nextcladePangoLineage:BA.5* would appear as [exactly-5-of: S:346, S:356, S:444, S:445, S:450, S:446, S:452, S:460, S:486...

Desired behavior:

Would it be nicer to have the three dots in the middle instead of at the end? I don't have a good reason or evidence but just a feeling.

For the above example, we'd have [exactly-5-of: S:346, S:356, S:444, S:4...ade:21K & nextcladePangoLineage:BA.5*

typo in example data

The example datasets for "plotName": "sequences-over-time_collection" all have a typo, "ProportionCIHigh" should be "proportionCIHigh"

Show the collection number

Current behavior:

image

Desired behavior:

Write "Collection #54 'RBD mutation number buckets relative to BA.2'"

Title should use the full width

Current behavior:

image

Desired behavior:

The title should use the full width of the output file (which is configurable) and only truncate if needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.