I have an interactive plot on rshiny and I would like the axes to scale dynamically depending on where user zoomed. I think I can use scale_y_continuous
for that using dynamic elements for ylim, however then I need to know the lower and upper y value of users current frame (where has been zoomed). Is there a way to achieve this with ggplot/rshiny?
require(shiny)
library(dplyr)
library(ggplot2)
ui <- fluidPage(
titlePanel(title=h4("example", align="center")),
mainPanel(plotlyOutput("plot"))
)
##server
server <- function(input,output){
dat<-reactive({
num<-c(1,2,3,4,5,6,7,8,9)
let<-c("A","B","C","D","E","F","G","H","I")
df<-data.frame(num,let)
df
})
output$plot<-renderPlotly({
gg <- ggplot(dat(),aes(x=let,y=num))+geom_point(aes(colour='red'))
gg2 <- ggplotly(gg) %>% layout(dragmode="select")
gg2
})
}
shinyApp(ui = ui, server = server)