I have an R Shiny dashboard with 2 tabs. Each tab displays a raster. Image query works on the first tab, but not on the second. On the second tab it shows a small empty space where the queried data should be displayed, but no values. If I remove the image query from the first tab, then it works on the second. I have ensured I have the latest updates of all the required packages. I am running the latest RStudio (1.2.5001) and R (3.6.1). Any help is appreciated.
I have created a minimal example shinyapp for which the image query fails on the second tab:
library(raster)
library(leaflet)
library(shiny)
library(leafem)
library(shinydashboard)
filename <- system.file("external/test.grd", package="raster")
r <- raster(filename)
r2 <- r*2
#Set up the Shiny app
ui <-function(request) {dashboardPage(
dashboardHeader(title="Test"),
dashboardSidebar(
sidebarMenu(
menuItem("Tab1", tabName = "Tab1"),
menuItem("Tab2", tabName = "Tab2")
)
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "Tab1",
leafletOutput("MyMap")
),
# Second tab content
tabItem(tabName = "Tab2",
leafletOutput("MyMap2")
)
)
)
)}
server <- function(input, output, session) {
#Draw the first map
output$MyMap <- renderLeaflet({
leaflet() %>%
addRasterImage(r,layerId= "A") %>%
addImageQuery(r, position="topleft", layerId = "A")
})
#Draw the second map
output$MyMap2 <- renderLeaflet({
leaflet() %>%
addRasterImage(r2,layerId= "B") %>%
addImageQuery(r2, position="bottomleft", layerId = "B")
})
}
shinyApp(ui, server)