shiny.R 907 B

1234567891011121314151617181920212223242526272829303132
  1. #' Render barcodes in Shiny applications
  2. #'
  3. #' @inheritParams shiny::renderImage
  4. #' @inheritParams shiny::imageOutput
  5. #' @param ... additional options passed to JsBarcode
  6. #' @importFrom jsonlite toJSON
  7. #' @importFrom shiny exprToFunction validateCssUnit
  8. #' @export
  9. #'
  10. #'
  11. renderBarcode <- function(expr, env=parent.frame(), quoted=FALSE, ...) {
  12. func <- shiny::exprToFunction(expr, env, quoted)
  13. options <- list(...)
  14. function() {
  15. val <- func()
  16. jsonlite::toJSON(list(barcode = val[1],
  17. options = options), auto_unbox = TRUE)
  18. }
  19. }
  20. #'@export
  21. #'@rdname renderBarcode
  22. #'@importFrom shiny tag
  23. #'
  24. barcodeOutput <- function(outputId, width = "100%", height = "400px") {
  25. style <- paste("width:", shiny::validateCssUnit(width), ";", "height:",
  26. shiny::validateCssUnit(height))
  27. tag("svg", list(id = outputId, style = style, class = "shiny-barcode-output"))
  28. }