R/mod_histogram.R

Defines functions mod_histogram_ui mod_histogram_server

Documented in mod_histogram_server mod_histogram_ui

# Module UI

#' @title   mod_histogram_ui and mod_histogram_server
#' @description  A shiny Module.
#'
#' @param id shiny id
#' @param input internal
#' @param output internal
#' @param session internal
#'
#' @rdname mod_histogram
#'
#' @keywords internal
#' @export 
#' @importFrom shiny NS tagList 
mod_histogram_ui <- function(id) {
  ns <- NS(id)
  plotOutput(ns("histogram"))
}

# Module Server

#' @rdname mod_histogram
#' @export
#' @keywords internal
mod_histogram_server <- function(input, output, session, image) {
  output$histogram <- renderPlot({
    color_df <- image() %>%
      reduce_pixel(100) %>%
      as.data.frame %>%
      mutate(color = c("r", "g", "b")[cc])
    ggplot(color_df, aes(x = value, fill = color)) +
      geom_histogram(position = "identity", bins = 64, alpha = 0.5, show.legend = FALSE) +
      scale_fill_manual(values = c(r = "red", g = "green", b = "blue"))
  })
}
igjit/lroom documentation built on Nov. 4, 2019, 1:55 p.m.