Hi
I have been gone through the discussion in this post. It is an interesting post for the shiny users. However, I have been facing similar problem in shiny using raster image. Since I am new in shiny, I vehemently need your help to resolve this. Any suggestions are welcome. I am attaching the code below.
rst <- raster('/home/prasenjit/Documents/prasenjit docs/ndvi_map.tif')
ui <- bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
leafletOutput("map", width = "100%", height = "100%"),
absolutePanel(top = 10, right = 10,
sliderInput("range", "ndvi", min(values(rst)), max(values(rst)),
value = range(values(rst)), step = 0.1)
#checkboxInput("legend", "Show legend", TRUE)
)
)
server <- function(input, output, session) {
filteredData <- reactive({
overlay(rst[[input$range]], fun = function(x){
if(
is.na() == T){x <- NA} else if(x >=input$range[1] && x <=input$range[2]){x*1} else(x <- NA)
})
})
pal <- colorNumeric("RdYlBu", values(rst),
na.color = "transparent")
output$map <- renderLeaflet({
leaflet() %>% addTiles() %>%
addRasterImage(rst, colors = pal, opacity = 1) %>%
addLegend(position = "bottomright", pal = pal, values = values(rst),
opacity = 1)
observe({
leafletProxy("map") %>%
clearImages() %>%
addRasterImage(filteredData(), colors = pal, opacity = 1)
})
})
}
shinyApp(ui, server)
Listening on http://127.0.0.1:3292
Warning: Error in inherits: cannot use this formula, probably because it is not vectorized
61: <Anonymous>