'R shiny renderLeaflet not rendering
I am trying to create an interactive map that displays locations only in the district chosen by the user in R shiny.
rm(list=ls())
library(readxl)
library(shiny)
library(tidyverse)
library(leaflet)
setwd("C:/Users/Dulguun Sukhbat/Desktop/intern")
data <- read_xlsx("data.xlsx",sheet = 1)
data <- data %>% select(-c(total.price,location,"location:"))
data <- na.omit(data)
attach(data)
data$LAT <- as.numeric(data$LAT)
data$LONG <- as.numeric(data$LONG)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("district","Select a district:",
choices = unique(data$district))
),
mainPanel(
tabsetPanel(
tabPanel("Map")
)
)
)
)
#server <- function(input, output) {
# dist_choice <- reactive({
#d <- data %>% filter(district == input$district)
# return(d)
# })
#dist_choice <- dist_choice %>% mutate(popup_info=paste("built - ",built,"<br/>","area - ",
# square,"<br/>","sq.price - ",sq.price))
# }
server <- function(input, output) {
dist_choice <- reactive({
data %>%
filter(district %in% input$district) %>%
mutate(popup_info = paste("built - ",built,"<br/>","area - ",
square,"<br/>","sq.price - ",sq.price))
})
output$Map <- renderLeaflet({
leaflet(dist_choice()) %>% addTiles() %>% addCircleMarkers(data = dist_choice(),
lat = ~LAT,lng = ~LONG,radius=1,popup = ~popup_info)
})
}
shinyApp(ui = ui, server = server)
There is no error message when I run the app, but the map doesn't show up. Please help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
