0

I have an interactive plot which has percentage total on the left hand side. For some reason, the y-axis is automatically re-sized to the maximum value of the input data frame (which makes total sense), however I would like to prevent this from happening and have the y-axis fixed at 0 to 100%. Can anyone tell me how I would do this?

library(shiny)
library(plotly)
library(scales)

ui <- fluidPage(
  sliderInput("rowSel", "Pick rows", min = 1, max = 10, val = 10),
  plotlyOutput("plot")
)

server <- function(input, output, session) {
  output$plot <- renderPlotly({
    p1 <- data.frame(x = 1:10,
                     y = seq(0.1, 1, 0.1)) %>% 
      filter(row_number() <= input$rowSel) %>% 
      ggplot(aes(x = x, y = y)) +
      geom_point() +
      scale_y_continuous(labels = label_percent(accuracy = 1L),
                         breaks = seq(from = 0, to = 1, by = 0.1))
    ggplotly(p1)
  })
}

shinyApp(ui, server)

enter image description here

zx8754
  • 46,390
  • 10
  • 104
  • 180
DJC
  • 1,303
  • 5
  • 12

0 Answers0