我正在尝试创建一个闪亮的应用程序,以在世界地图上显示栅格。用户将与输入进行交互,应用程序将生成栅格以及直方图。下面的代码生成直方图,但不生成地图,我需要帮助以进行排序。这是到目前为止的数据和我的进度。我收到的错误如下所示:input projection is NA
library(shiny)
library(tmap)
library(tmaptools)
library(raster)
library(leaflet)
library(dplyr)
coords <- structure(list(cell.lon = c(80,78.25,78.75,72.75,73,78.5,79.5,79.25,78.25),cell.lat = c(15.25,14.25,12.75,26.75,22,23.5,25,22.25,15.25,24)),class = c("tbl_df","tbl","data.frame"),row.names = c(NA,-10L))
dat.df <- expand.grid(cell.lon = coords$cell.lon,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()))
ui <- fluidPage(
titlePanel('My shiny'),sidebarLayout(position = 'left',sidebarPanel(
selectInput(inputId = 'seasonRef',label = 'Select season',choices = c('winter',selected = 'summer'),selectInput(inputId = 'businessRef',label = 'Select business',choices = c('train',selected = 'train'),radioButtons(inputId = 'var',label = NULL,choiceNames = c('modP',choiceValues = c('modP',width = '400px',selected = 'modP'),sliderInput('yearRef','Select Year',min=2001,max=2003,value=1)
),mainPanel(
tabsetPanel(
tabPanel('Map',leafletOutput("map")),tabPanel('Histogram',plotOutput(outputId = 'hist'))
))))
server <- function(input,output) {
tempI <- reactive({
temp <- dat.df1 %>% dplyr::filter(business == input$businessRef &
seasonID == input$seasonRef &
YearRef == input$yearRef &
variable == input$var)
temp.raster <- rasterFromXYZ(temp[,c('cell.lon','cell.lat','value')])
})
output$map <- renderLeaflet({
leaflet() %>% addTiles() %>% addRasterImage(tempI())
})
output$hist <- renderPlot({
hist(tempI())
})
}
shinyApp(ui,server)