The component's design is based on AngularJS, which can emit events from the root to its children and broadcast events from children to parents. It gives better structure to non-trivial Shiny apps that need to have many different parts.
From R:
devtools::install_github("Genentech/battery")From the source:
git clone https://github.com/Genentech/battery.git
R CMD INSTALL batteryButton <- battery::component(
classname = "Button",
label = NULL,
constructor = function(label = NULL) {
self$label <- label
},
render = function() {
shiny::tags$button(self$label)
}
)
App <- battery::component(
classname = "App",
public = list(
constructor = function() {
btn <- Button$new(label = "Click me", parent = self, component.name = "button")
self$output[[ self$ns("root") ]] <- shiny::renderUI({
shiny::tags$div(
shiny::tags$p("click the button"),
btn$render()
)
})
},
render = function() {
tags$div(
titlePanel('Shiny App using Battery R package'),
mainPanel(shiny::uiOutput(self$ns("root")))
)
}
)
)For full documentation see Battery Components Vignette.
You can also read tutorial about the framework features at DEV.to:
Architecture for Non-Trivial R Shiny Applications
- Jakub T. Jankiewicz - main author
- Michał Jakubczak
Copyright (c) 2019-2021 Genentech, Inc.
Released under the MIT License. See LICENSE.md for the full text.