Add a Zoom on my plot

shiny
rstudio

#1

I guys, i'm actually trying to add a zoom function on my plot but I don't understand how to do it, can someone help me please? I used the shiny zoom tutoriel but never made it work (https://shiny.rstudio.com/gallery/plot-interaction-zoom.html)

This is my code, thanks in advance :

ui = fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("inputFile", "Browse for file",multiple = TRUE),
uiOutput("plot.params")
),
mainPanel(
tabsetPanel(
tabPanel("graph",plotOutput("plot"))
)
)
)
)

server<-function(input, output, session) {

data_set <- reactive({
if(is.null(input$inputFile)){
return(NULL)}
data_set<-read.table(input$inputFile$datapath,sep=";",header = FALSE)

})

output$plot.params <- renderUI({ list(
selectInput(inputId = "xaxisGrp", label = "X", choices = names(data_set() )) ,
selectInput(inputId = "yaxisGrp", label = "Y", choices = names(data_set() ))
)})

output$plot = renderPlot({
df <- data_set()
gp <- NULL
if (!is.null(df)){
xv <- input$xaxisGrp
yv <- input$yaxisGrp
if (!is.null(xv) & !is.null(yv)){
if (sum(xv %in% names(df))>0){
mdf <- melt(df,id.vars=xv,measure.vars=yv)
gp <- ggplot(data=mdf, aes_string(x=xv,y="value")) +
geom_point()
}
}
}
return(gp)
})
}

shinyApp(ui,server)


#2

Could you reformat your question as a reproducible example (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help. A lack of a reprex just makes it much less likely others will reply.
Here's how to format your code chunk: FAQ: How to make your code look nice? Markdown Formatting

Be sure to include the error messages or issues you're facing.

Your code above runs for me, but deviates from the example linked.