在shapefile上以闪亮的R显示光栅
我正试图在我闪亮的应用程序中的shapefile上显示光栅。这是我的方法在shapefile上以闪亮的R显示光栅,r,shiny,raster,shapefile,R,Shiny,Raster,Shapefile,我正试图在我闪亮的应用程序中的shapefile上显示光栅。这是我的方法 # Load libraries and create sample data library(raster) library(shiny) library(dplyr) library(leaflet) library(ggplot2) library(ggthemes) library(tmap) fr.shp <- getData('GADM', country='FRA'
# Load libraries and create sample data
library(raster)
library(shiny)
library(dplyr)
library(leaflet)
library(ggplot2)
library(ggthemes)
library(tmap)
fr.shp <- getData('GADM', country='FRA', level=1)
coords <- data.frame(coordinates(fr.shp))
names(coords) <- c('lon', 'lat')
dat.df <- expand.grid(lon = coords[, 1],
seasonID = c('winter', 'summer'),
business = c('train', 'bus', 'taxi'),
variable = c('modP', 'modT'),
YearRef = 2001:2003)
dat.df1 <- coords %>% dplyr::left_join(dat.df) %>% dplyr::mutate(value = rnorm(n()))
#加载库并创建示例数据
图书馆(光栅)
图书馆(闪亮)
图书馆(dplyr)
图书馆(单张)
图书馆(GG2)
图书馆(主题)
图书馆(tmap)
fr.shp但您链接的帖子的答案确实允许您在基于地图视图
或传单
的解决方案中使用自己的光栅和多边形图层。在你闪亮的应用程序中使用这些方法是可能的,但不是真的。本文介绍了如何将现有光栅添加到shapefile中。在我的例子中,我没有光栅,需要根据用户输入动态生成光栅。
ui <- fluidPage(
titlePanel('my shiny'),
sidebarLayout(position = 'left',
sidebarPanel(
selectInput(inputId = 'seasonRef', label = 'Select season', choices = c('winter','summer'), selected = 'Kharif'),
selectInput(inputId = 'transport', label = 'Select transport',
choices = c('train','bus','taxi'), selected = 'train'),
checkboxGroupInput(inputId = 'type', label = NULL,
choiceNames = c('modP','modT'),
choiceValues = c('modP','modT'),
width = '400px', selected = 'modP'),
sliderInput('yearRef','Select Year',min=2001,max=2003,value=1)
),
mainPanel(
tabsetPanel(
tabPanel('myplots', plotOutput(outputId = 'rast')),
leafletOutput("my_tmap")
)
)
)
)
server <- function(input, output) {
tempI <- reactive({dat.df1 %>% dplyr::filter(seasonID == input$seasonRef &
business == input$transport &
YearRef == input$yearRef &
variable == input$type)})
output$rast <- renderPlot({
ggplot() + geom_raster(data = tempI(), aes(x = lon, y = lat, fill = value)) +
theme_map() + coord_equal() + scale_fill_viridis_c(option = 'C')
})
# tmap_mode("view")
# output$my_tmap = renderLeaflet({
# qtm(fr.shp)})
}
shinyApp(ui, server)