mapview für shiny

Ich erstelle eine interaktive Karte mitmapView

dasmapview() -Funktion funktioniert gut mit meinen gerasterten Daten SpatialPixelsDataFrame):

Code
library(sp)
library(ggplot2)
library(gstat)
library(rgdal)
library(mapview)
library(RMySQL)

con <- dbConnect(MySQL(),
                 user="root",
                 password="",
                 host="127.0.0.1",
                 dbname="rstudio")
data<-dbReadTable(con,"data")
on.exit(dbDisconnect(con))

data_test <- data
data_test$x <- data$long
data_test$y <- data$lat
coordinates(data_test) = ~x + y
x.range <- as.numeric(c(-5.99, -5.74))  
y.range <- as.numeric(c(35.57, 35.81))  
grd <- expand.grid(x = seq(from = x.range[1], to = x.range[2], by = 0.002), 
                   y = seq(from = y.range[1], to = y.range[2], by = 0.002))  # expand points to grid
coordinates(grd) <- ~x + y
gridded(grd) <- TRUE

idw <- idw(formula = temp ~ 1, locations = data_test, newdata = grd)
idw.output = as.data.frame(idw)  # output is defined as a data table

names(idw.output)[1:3] <- c("long", "lat", "temp")
idw.output <- idw.output[,1:3]

coordinates(idw.output) <- ~long+lat
morocco <- readOGR("Data/morocco/TNG", "TNG")
proj4string(idw.output)<-proj4string(morocco)
tempData <- idw.output[morocco,]
proj4string(data_test)<-proj4string(morocco)
gridded(tempData) <- TRUE
m<-mapView(tempData, zcol = "temp") + data_test
m
Ergebnis

Jetz

Ich möchte auf Shiny umsteigen. Das Problem ist, dass es keine Renderfunktion für die Kartenansicht gibt. Ich habe versucht, fpView () bView () zu verwenden, aber kein Ergebnis.

Mein Versuch mit ShinyCode ui.R
library(shiny)
library(shinydashboard)
library(mapview)

header <- dashboardHeader(title="Ardusky")

sidebar <- dashboardSidebar(
)

body <- dashboardBody(
  # Define UI for application
  fluidPage(
    mainPanel(
      mapview:::fpViewOutput("mapplot"),
      mapview:::plainViewOutput("test")
    ))
)

ui <- dashboardPage(header, sidebar, body, skin="black")
server.R
library(shiny)
library(mapview)
library(ggplot2)
library(sp)
library(gstat)
library(rgdal)
library(RMySQL)

shinyServer(function(input, output, session) {

  repInput <- reactive({
                    con <- dbConnect(MySQL(),
                                     user="root",
                                     password="",
                                     host="127.0.0.1",
                                     dbname="rstudio")
                    data<-dbReadTable(con,"data")
                    on.exit(dbDisconnect(con))
                    data_test <- data
                    data_test$x <- data$long
                    data_test$y <- data$lat
                    coordinates(data_test) = ~x + y
                    x.range <- as.numeric(c(-5.99, -5.74))  
                    y.range <- as.numeric(c(35.57, 35.81))  
                    grd <- expand.grid(x = seq(from = x.range[1], to = x.range[2], by = 0.002), 
                                       y = seq(from = y.range[1], to = y.range[2], by = 0.002))  # expand points to grid
                    coordinates(grd) <- ~x + y
                    gridded(grd) <- TRUE
                    idw <- idw(formula = temp ~ 1, locations = data_test, newdata = grd)
                    idw.output = as.data.frame(idw)  # output is defined as a data table
                    names(idw.output)[1:3] <- c("long", "lat", "temp")
                    idw.output <- idw.output[,1:3]
                    coordinates(idw.output) <- ~long+lat
                    morocco <- readOGR("/home/bloodesu/Data/morocco/TNG", "TNG")
                    proj4string(idw.output)<-proj4string(morocco)
                    tempData <- idw.output[morocco,]
                    proj4string(data_test)<-proj4string(morocco)
                    gridded(tempData) <- TRUE
                    tempData
  })

  output$mapplot <- mapview:::renderfpView({
    mapview:::fpView(repInput(), zcol = "temp")
  })

  output$test <- mapview:::renderPlainView({
    mapview:::plainview(repInput(), zcol = "temp")
  })


})
Ergebni

Fazi

Wie Sie sehen können, liefert nur die plainView einige akzeptable Ergebnisse, jedoch ohne Unterstützung für Broschüren

Antworten auf die Frage(2)

Ihre Antwort auf die Frage