#' Old Faithful histogram Shiny module
#'
#' @description UI and server function for an example Shiny module.
#'
#' @param id Internal parameter for {shiny}.
#' @param variable character variable name.
#'
#' @name mod_faithful_histogram
#'
NULL
#' @rdname mod_faithful_histogram
#'
#' @import shiny
mod_faithful_histogram_ui <- function(id) {
ns <- NS(id)
tagList(
fluidRow(
column(
3,
sliderInput(
ns("bins"), "Number of bins:",
min = 1, max = 50, value = 30
),
checkboxInput(
ns("density"),
"density"
)
),
# Show a plot of the generated distribution
column(
9,
plotOutput(ns("distPlot"))
)
)
)
}
#' @rdname mod_faithful_histogram
mod_faithful_histogram_server <- function(id, variable = NULL){
moduleServer( id, function(input, output, session){
ns <- session$ns
# generate bins based on input$bins from ui.R
x <- datasets::faithful[, variable]
bins <- reactive(seq(min(x), max(x), length.out = input$bins + 1))
output$distPlot <- renderPlot({
# draw the histogram with the specified number of bins
plot_hist(x = x, breaks = bins(), freq = !input$density)
})
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.