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.
 
 

55 lines
1.5 KiB

#' barplot UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
#' @importFrom plotly plotlyOutput renderPlotly ggplotly
#' @importFrom ggplot2 ggplot aes geom_col geom_text labs theme_classic scale_y_continuous theme position_stack
#' @importFrom scales unit_format
mod_barplot_ui <- function(id){
ns <- NS(id)
tagList(
shinycssloaders::withSpinner(
type = 5,
hide.ui=F,
plotly::plotlyOutput(ns("barplot"))
)
)
}
#' barplot Server Functions
#'
#' @noRd
mod_barplot_server <- function(id, dat, ttl, cptn="Source: Download from SAP", ny=3000000){
moduleServer( id, function(input, output, session){
ns <- session$ns
output$barplot<- plotly::renderPlotly({
validate(
need(nrow(dat)>0, 'Wait. Wrong button. There is nothing here. CLick something else.')
)
pl<-ggplot(dat, aes(x=name, y=amount, label=paste0(round(amount/1000000,1)," M")))+
geom_col(fill="blue")+
geom_text(col="black", nudge_y = ny)+
scale_y_continuous(labels = unit_format(unit = "M", scale = 1e-6))+
labs(title=ttl,
subtitle = "",
y="amount",
x="",
caption=cptn)+
theme_classic()
ggplotly(pl)
})
})
}
## To be copied in the UI
# mod_barplot_ui("barplot_ui_1")
## To be copied in the server
# mod_barplot_server("barplot_ui_1")