Use shiny ui function overlayed on static chart

Hi. New here

If i take below shiny as my base example

I would like to leave the max value displayed barchart and have the renderplot drop the bar values in respoce to the input bin

In essance full static chart in blue and overlayed onto that the dynamic chart in light blue.

So when user selects slide bar they see max value along with superimposed lowering chart.

Do you think this is possible

library(shiny)
library(tidyverse)
# Define UI for app that draws a histogram ----
ui <- fluidPage(
  
  # App title ----
  titlePanel("Hello Shiny!"),
  
  # Sidebar layout with input and output definitions ----
  sidebarLayout(
    
    # Sidebar panel for inputs ----
    sidebarPanel(
      
      # Input: Slider for the number of bins ----
      sliderInput(inputId = "bins",
                  label = "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
      
    ),
    
    # Main panel for displaying outputs ----
    mainPanel(
      
      # Output: Histogram ----
      plotOutput(outputId = "distPlot")
      
    )
  )
)

# Define server logic required to draw a histogram ----
server <- function(input, output) {
  
  # Histogram of the Old Faithful Geyser Data ----
  # with requested number of bins
  # This expression that generates a histogram is wrapped in a call
  # to renderPlot to indicate that:
  #
  # 1. It is "reactive" and therefore should be automatically
  #    re-executed when inputs (input$bins) change
  # 2. Its output type is a plot
  output$distPlot <- renderPlot({
    
    x    <- faithful$waiting
    bins <- input$bins
    max_count <- nrow(faithful)
    # hist(x, breaks = bins, col = "#75AADB", border = "white",
    #      xlab = "Waiting time to next eruption (in mins)",
    #      main = "Histogram of waiting times")
    ggplot(data = select(faithful,waiting)) +
      aes(x=waiting) +
      ylim(c(0,max_count))+
      geom_histogram(bins=bins, alpha=.5, fill="#6699FF")+
      geom_histogram(bins=50, alpha=.5) +
      xlab("Waiting time to next eruption (in mins)") +
      ggtitle("Histogram of waiting times") 
  })
  
}

# Create Shiny app ----
shinyApp(ui = ui, server = server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.