Coder Social home page Coder Social logo

appsilon / shiny.benchmark Goto Github PK

View Code? Open in Web Editor NEW
30.0 5.0 2.0 1013 KB

Tools to measure performance improvements in shiny apps

Home Page: https://appsilon.github.io/shiny.benchmark/

R 87.50% JavaScript 8.83% Shell 1.72% CSS 1.95%
performance-testing r shiny rhinoverse

shiny.benchmark's Introduction

shiny.benchmark shiny.benchmark logo

Tools to measure performance improvements in shiny apps.

CRAN status R-CMD-check

shiny.benchmark is a tool aimed to measure and compare the performance of different versions of a shiny application. Based on a list of different application versions, accessible by a git repo by its refs (commit hash or branch name), the user can write instructions to be executed using Cypress or shinytest2. These instructions are then evaluated by the different versions of your shiny application and therefore the performance's improvement/deterioration (time elapsed) are be recorded.

The package is flexible enough to allow different sets of tests for the different refs as well as different package versions (via renv). Also, the user can replicate the tests to have more accurate measures of performance.

How to install?

Stable version:

install.packages("shiny.benchmark")

Development version:

remotes::install_github("Appsilon/shiny.benchmark")

Dependencies

shiny.benchmark can use two different engines to test the change in the performance of your application: shinytest2 and Cypress. The latter requires Node (version 12 or higher) and yarn (version 1.22.17 or higher) to be available. To install them on your computer, follow the guidelines on the documentation pages:

Besides that, on Linux, it might be required to install other Cypress dependencies. Check the documentation to find out more.

How to use it?

The best way to start using shiny.benchmark is through an example. If you want a start point, you can use the load_example function. In order to use this, create a new folder in your computer and use the following code to generate an application to serve us as example for our performance checks:

library(shiny.benchmark)

load_example(path = "path/to/new/project")

It will create some useful files under path/to/new/project. The most important one is the run_tests.R which provides several instructions at the very top.

As we are comparing versions of the same application, we need different app versions in different branches/commits in git. Start using cd app; git init to initiate git inside app/ folder.

Get familiar with app/server.R file in order to generate more interesting scenarios. The basic idea is to use the Sys.sleep function to simulate some app's functionalities. Remember that, when running the benchmark, that is the amount of time it will take to measure the performance.

When you are ready, commit your changes in master/main using git add .; git commit -m "your commit message". Make some editions and commit these new changes into a new branch or in the same branch your are testing (it will have a different commit hash). Repeat the process adding as many new modifications as you want. E.g. add renv, add more tests, change the names of the tests/test files and so on.

Here is a complete example on how to setup your git:

# starting
git init
echo .Rproj.user >> .gitignore
echo *.Rproj >> .gitignore
echo .Rprofile >> .gitignore
echo renv >> .gitignore
echo .Rprofile >> .gitignore

# master
git add .
git commit -m "first commit"

# develop (decrease Sys.sleep times in server.R)
git checkout -b develop
git add .
git commit -m "improving performance"

## Using renv
git branch renv_shiny1 develop
git checkout renv_shiny1
R -e 'renv::init()'
git add .
git commit -m "renv active"

## Downgrading shiny
git checkout -b renv_shiny2
R -e 'renv::install("[email protected]")'
R -e 'renv::snapshot()'
git add .
git commit -m "downgrading shiny"

## Switching back to develop
git checkout develop

Now you are ready to go. The benchmark function provides several arguments to make your life easier when running your performance checks. The mandatory arguments are:

  • commit_list: A vector with commits, branches or anything else you can use in git checkout
  • cypress_dir or shinytest2_dir: Folder containing the tests we want to check the performance. In our case it is tests/cypress and tests respectively.

The default behavior is to try to use renv in your project. If you do not have the renv structure, you can turn renv off using use_renv = FALSE

library(shiny.benchmark)

# commits to compare
commit_list <- c("develop", "renv_shiny1", "renv_shiny2")

# run performance check using Cypress
benchmark(
  commit_list = commit_list,
  cypress_dir = "tests/cypress"
)

That is all you need to run your Cypress tests. If you don't use Cypress, you may want to use shinytest2 instead:

benchmark(
  commit_list = commit_list,
  shinytest2_dir = "tests"
)

To run just specific tests, you can take advantage of the tests_pattern argument. It will filter the test file's names based on regular expression:

benchmark(
  commit_list = commit_list,
  shinytest2_dir = "tests",
  tests_pattern = "use_this_one_[0-9]"
)

If your project has renv structure, you can set use_renv to TRUE to guarantee that, for each application version your are using the correct packages. If you want to approve/reprove renv::restore(), you can set renv_prompt = TRUE.

benchmark(
  commit_list = commit_list,
  shinytest2_dir = "tests",
  tests_pattern = "use_this_one_[0-9]",
  use_renv = TRUE, # default
  renv_prompt = TRUE
)

To have more accurate information about the time your application takes to perform some actions, you may need to replicate the tests. In this case, you can use the n_rep argument:

out <- benchmark(
  commit_list = commit_list,
  cypress_dir = "tests/cypress",
  tests_pattern = "use_this_one_[0-9]",
  use_renv = FALSE,
  n_rep = 15
)

out

For fast information about the tests results, you can use the summary and also the plot methods:

summary(out)
plot(out)

How to contribute?

If you want to contribute to this project please submit a regular PR, once you're done with new feature or bug fix.

Reporting a bug is also helpful - please use GitHub issues and describe your problem as detailed as possible.

Appsilon

Appsilon is a Posit (formerly RStudio) Full Service Certified Partner.
Learn more at appsilon.com.

Get in touch [email protected]

Explore the Rhinoverse - a family of R packages built around Rhino!

We are hiring!

shiny.benchmark's People

Contributors

averissimo avatar douglasmesquita avatar jakubnowicki avatar marekrogala avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

insightsurge

shiny.benchmark's Issues

Improve README file

Add information such as:

  • How to install the package
  • What are the mandatory setup
  • How to install Cypress in your machine
  • How to use the package

Define package name, color and animal

Animals:

List of the fastest animals in the earth:
https://en.wikipedia.org/wiki/Fastest_animals#:~:text=10%20References-,Fastest%20organism,conflicting%20reports%20of%20recorded%20speeds.

Peregrine Falcon - Fastest animal on earth
Cheetah - Fastest land animal on earth

Package name:

shiny.beanchmark
shiny.performance

Color:
Red (#FF0000) is the fastest color in a vacuum space
Violet (#8F00FF) is the slowest color in a vacuum space

f <- colorRampPalette(colors = c("#FF0000", "#8F00FF"))
f(3)[2]

Last test does not work in Cypress

For some reason the last test in the Cypress list of tests does not works. It does not appear in the final list of time measurements.

Create an app and git setup to allow testing all the functionalities of this package

It is a little bit trick to test the functionalities of this package since we need an application and several branches with different setups. Therefore, it would be great to create a script able to setup an example application and all the characteristics desired (renv/no renv, single file/multiple files, no repetition/several repetitions, ...).

Update repo name

Update repo name so GitHub actions can run the tests properly

Remove git2r dependency

Right now git2r is not needed since most of the git functions are done by system("code") and we only need simple functions. With time we may need some more complex solutions and then we can reconsider using git2r. Right now it is only increasing complexity.

Improve error messages

Test can fail because of different problems e.g.:

  • not able to find the desired commit
  • not able to run renv::restore
  • not able to find the set of tests
  • permission issues

We should be able to inform the user the source of the error

Always run tests in a temporary folder

We do not want to add/remove files from the current git folder. In this case, it is preferable to run all the tests in a temporary folder. It will work unless we have hard coded paths in the application.

Fix current lint issues

The beta version has some lint issues. Fix it using linter package and keep it organized for the further implementions

Allow for different tests in different branches

Allow user to provide:

  • single test file (run the same set of test in all branches)
  • multiple test files as input (run specific tests for each branch)
  • multiple test files stored in the specific commit (tests/ folder)

Improve logs (INFO, DEBUG, WARNINGS)

Right now it is impossible to run the tests in silent mode. It will be better to have something like options(shiny.performance.logs = "debug") info, error and so on...

Create a report template

It should be a Quarto template. The main idea is to have a wrapper like shiny.performance::create_report("path_to_report.md") and shiny.performance::render_report("path_to_report.md"). This way, the user can edit the path_to_report.md file instead of just observing the result.

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.