Skip to content

Repository files navigation

JsBarcode JsBarcode logo: a CODE128 barcode on a blue hexagon

R-CMD-check lint pkgdown R >= 3.5.0 License: MIT

Barcode widgets for R. JsBarcode wraps the JsBarcode JavaScript library (v3.12.3) as an htmlwidget, so you can render 1D barcodes as SVG in the RStudio viewer, R Markdown / Quarto documents and Shiny apps.

Documentation: https://EnriquePH.github.io/JsBarcode/

Installation

# install.packages("remotes")
remotes::install_github("EnriquePH/JsBarcode")

Usage

library(JsBarcode)

JsBarcode("Hello world")                                   # CODE128 (default)
JsBarcode("5901234123457", format = "EAN13")               # EAN-13
JsBarcode("123456", bar_height = 40, display_value = FALSE)
JsBarcode("ABC-123", line_color = "#1a4f8b", background = "transparent")

# Any other JsBarcode option can be passed with its JavaScript name
JsBarcode("Label", textAlign = "left", textPosition = "top", flat = TRUE)

Supported formats are listed in barcode_formats: CODE128 (A/B/C), EAN-13, EAN-8, EAN-5, EAN-2, UPC-A, UPC-E, CODE39, CODE93, CODE93 Full ASCII, ITF, ITF-14, MSI (10/11/1010/1110), Pharmacode and Codabar. barcode_format_info describes each one (accepted characters, length, check digit, typical use and a valid example). Only linear (1D) barcodes are supported; QR Code, Data Matrix, PDF417 and other 2D codes are not.

If a value is not valid for the chosen format (e.g. letters in EAN-13), the widget shows an inline error message instead of a barcode.

Shiny

library(shiny)

ui <- fluidPage(JsBarcodeOutput("code"))
server <- function(input, output) {
  output$code <- renderJsBarcode(JsBarcode("Hello Shiny"))
}
shinyApp(ui, server)

A complete demo ships with the package:

shiny::runApp(system.file("examples/shiny", package = "JsBarcode"))

From a clone of the repository:

scripts/run-app.sh            # installed package (reinstalls if the source is newer)
scripts/run-app.sh --dev      # straight from source, no install
scripts/run-app.sh --port 4000 --browser

Development

Common tasks are wrapped in a Makefile (make help lists them):

make lint      # lint with lintr (rules in .lintr)
make test      # run the test suite
make check     # full R CMD check
make run       # launch the Shiny demo on port 3838 (make run-dev: from source)
make site      # build the pkgdown site into docs/
make update-js # vendor the latest JsBarcode from npm

CI runs R CMD check on every push and pull request against five configurations: R release on Ubuntu, macOS and Windows, plus R devel and R oldrel-1 on Ubuntu. A separate workflow runs lintr and fails on any lint. Every push to main rebuilds the documentation site and deploys it to the gh-pages branch. See the Development and CI/CD article for details.

License

MIT. The bundled JsBarcode library is © Johan Lindell, MIT licensed (inst/htmlwidgets/lib/jsbarcode-3.12.3/LICENSE).

About

Barcode widgets for R. JsBarcode wraps the JsBarcode JavaScript library (v3.12.3) as an htmlwidget

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages