You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
#' stackedbarplot UI Function
|
|
#'
|
|
#' @description A shiny Module.
|
|
#'
|
|
#' @param id,input,output,session Internal parameters for {shiny}.
|
|
#'
|
|
#' @noRd
|
|
#'
|
|
#' @importFrom shiny NS tagList
|
|
mod_stackedbarplot_ui <- function(id){
|
|
ns <- NS(id)
|
|
tagList(
|
|
shinycssloaders::withSpinner(
|
|
type = 5,
|
|
hide.ui=F,
|
|
plotly::plotlyOutput(ns("stabarplot"))
|
|
)
|
|
)
|
|
}
|
|
|
|
#' stackedbarplot Server Functions
|
|
#'
|
|
#' @noRd
|
|
mod_stackedbarplot_server <- function(id, dat, ttl, cptn="Source: Download from SAP", ny=2000000){
|
|
moduleServer( id, function(input, output, session){
|
|
ns <- session$ns
|
|
output$stabarplot<- plotly::renderPlotly({
|
|
pl<-ggplot(dat, aes(x=name, y=amount, fill=bp_category, label=paste0(round(amount/1000000,1)," M")))+
|
|
geom_col(position="stack")+
|
|
geom_text(col="black", size=3, angle = 45, position = position_stack(vjust = 0.5),check_overlap = TRUE)+
|
|
scale_y_continuous(labels = unit_format(unit = "M", scale = 1e-6))+
|
|
labs(title=ttl,
|
|
subtitle = "",
|
|
y="amount",
|
|
x="",
|
|
caption=cptn)+
|
|
theme_classic()+
|
|
theme(
|
|
legend.position="bottom"
|
|
)
|
|
ggplotly(pl)
|
|
})
|
|
|
|
})
|
|
}
|
|
|
|
## To be copied in the UI
|
|
# mod_stackedbarplot_ui("stackedbarplot_ui_1")
|
|
|
|
## To be copied in the server
|
|
# mod_stackedbarplot_server("stackedbarplot_ui_1")
|
|
|