R/mod_plotting.R

Defines functions mod_plotting_server mod_plotting_ui

#' plotting UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_plotting_ui <- function(id){
  ns <- NS(id)
  tagList(
    shiny::sidebarLayout(
      shiny::sidebarPanel(
        shiny::textAreaInput(
          inputId = ns("peptide"),
          label = "Peptide sequence",
          width = 300,
          height = 100,
          placeholder = "Insert peptide sequence"
        )
      ),
      shiny::mainPanel(
        shiny::plotOutput(
          outputId = ns("abundance")
        )

      )
    )
  )
}

#' plotting Server Functions
#'
#' @noRd
mod_plotting_server <- function(id){
  moduleServer( id, function(input, output, session){
    ns <- session$ns
    #Plotting module server logic
    observeEvent(input$peptide, {
      output$abundance <- renderPlot({
        if(input$peptide == ""){
          NULL
        } else{
          input$peptide %>%
            biocentral:::seq_count() +
            ggplot2::theme(legend.position = "none")
        }
      })
    })
  })
}

## To be copied in the UI
# mod_plotting_ui("plotting_1")

## To be copied in the server
# mod_plotting_server("plotting_1")
rforbiodatascience22/group_1_shiny documentation built on April 10, 2022, 11:05 a.m.