I'm fairly new to Shiny so I'm sure there is a better way to do this.....The basic idea is to display an image and then run the flood fill segmentation algorithm from imager (px.flood) where the user selects the seed pixel from a mouse click and sets the tolerance level with a sliderInput.....The app works, but I can only figure out how to get the segmentation to display on a 2nd plotOutput....not sure if there is a way to include this all in one plot window, so when a user clicks on a pixel, the flood fill segmentation redraws and appears in the same plot?
Here is the code with the boats image that comes with the imager package:
library(shiny)
library(imager)
ui <- fluidPage(
sliderInput(inputId='sig',label = "tolerance:",min = 0,max = 1,value = .2),
plotOutput("plot1", click = "plot_click"),
plotOutput("plot2")
)
server <- function(input, output) {
output$plot1 <- renderPlot({
plot(boats) })
output$plot2=renderPlot({
plot(boats)
px=px.flood(boats,input$plot_click$x,input$plot_click$y,sigma=input$sig)
highlight(px)
})
}
shinyApp(ui, server)