#' barchart UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_barchart_ui <- function(id){
ns <- NS(id)
tagList(
plotly::plotlyOutput(ns('barchart'))
)
}
#' barchart Server Functions
#'
#' @noRd
mod_barchart_server <- function(id,metric,title= NULL,xtitle = NULL,ytitle = NULL,facet = NULL){
moduleServer( id, function(input, output, session){
ns <- session$ns
if(rlang::is_null(facet) == TRUE){
toplot <- dataset %>% dplyr::count(.data[[metric]])
output$barchart <- plotly::renderPlotly({
p <- plotly::plot_ly(toplot, x = ~.data[[metric]],y = ~n)
p <- plotly::add_bars(p)
p <- plotly::layout(p, # all of layout's properties: /r/reference/#layout
title = title, # layout's title: /r/reference/#layout-title
xaxis = list( # layout's xaxis is a named list. List of valid keys: /r/reference/#layout-xaxis
title = xtitle, # xaxis's title: /r/reference/#layout-xaxis-title
showgrid = F), # xaxis's showgrid: /r/reference/#layout-xaxis-showgrid
yaxis = list( # layout's yaxis is a named list. List of valid keys: /r/reference/#layout-yaxis
title = ytitle) # yaxis's title: /r/reference/#layout-yaxis-title
)
p
})
}
})
}
## To be copied in the UI
# mod_barchart_ui("barchart_ui_1")
## To be copied in the server
# mod_barchart_server("barchart_ui_1")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.