can't find variable from a dataframe when try to call in addCircleMarker in R shiny leaflet
up vote
0
down vote
favorite
I have a dataset that have the long and lat information, as well as the 'Experiment' info for each long and lat.
I used addCircleMarkers to add markers. And I want to have popup options for each marker. I tried to call "Experiment" at popup, but it gives me errors that it can't find this variable. I am not sure where it went wrong.
Dataset
ui <- fluidPage(
titlePanel("Land Explorer"),
selectInput("year", "Year of G2F", choices = c("2014", "2015", "2016", "All")),
fluidRow(
mainPanel(
tags$style(type = "text/css", "#map {height: calc(100vh - 80px) !important;}"),
leafletOutput("map"), width = "100%", height = 1000)
)
)
server <- function(input, output){
pal <- colorFactor("RdYlGn", county_simplified$zone, reverse = T, na.color = "white")
state_popup <- paste0("<strong>State: </strong>",
county_simplified$region,
"<br><strong>County: </strong>",
county_simplified$subregion)
g2f <- reactive ({
if (input$year == "2014"){
g2f_latlong = g2f_latlong[g2f_latlong$year == 2014, ]
}
else if (input$year == "2015"){
g2f_latlong = g2f_latlong[g2f_latlong$year == 2015, ]
}
else if (input$year == "2016") {
g2f_latlong = g2f_latlong[g2f_latlong$year == 2016, ]
}
else if (input$year == "All"){
g2f_latlong = g2f_latlong
}
else (g2f_latlong = g2f_latlong)
})
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addPolygons(data = county_simplified, weight = 1,
color = "white",
dashArray = '3',
fillOpacity = 0.7,
fillColor = ~pal(zone),
popup = state_popup) %>%
addPolygons(data = state_boundry, weight = 1, color = "grey", fill = NA) %>%
addLegend(pal = pal, value = county_simplified$zone, position = "topright", title = "Zones") %>%
addCircleMarkers(data = g2f(), lng = ~long, lat = ~lat, popup = ~Experiment, radius = 1)
})
}
shinyApp(ui = ui, server = server)
r shiny leaflet
add a comment |
up vote
0
down vote
favorite
I have a dataset that have the long and lat information, as well as the 'Experiment' info for each long and lat.
I used addCircleMarkers to add markers. And I want to have popup options for each marker. I tried to call "Experiment" at popup, but it gives me errors that it can't find this variable. I am not sure where it went wrong.
Dataset
ui <- fluidPage(
titlePanel("Land Explorer"),
selectInput("year", "Year of G2F", choices = c("2014", "2015", "2016", "All")),
fluidRow(
mainPanel(
tags$style(type = "text/css", "#map {height: calc(100vh - 80px) !important;}"),
leafletOutput("map"), width = "100%", height = 1000)
)
)
server <- function(input, output){
pal <- colorFactor("RdYlGn", county_simplified$zone, reverse = T, na.color = "white")
state_popup <- paste0("<strong>State: </strong>",
county_simplified$region,
"<br><strong>County: </strong>",
county_simplified$subregion)
g2f <- reactive ({
if (input$year == "2014"){
g2f_latlong = g2f_latlong[g2f_latlong$year == 2014, ]
}
else if (input$year == "2015"){
g2f_latlong = g2f_latlong[g2f_latlong$year == 2015, ]
}
else if (input$year == "2016") {
g2f_latlong = g2f_latlong[g2f_latlong$year == 2016, ]
}
else if (input$year == "All"){
g2f_latlong = g2f_latlong
}
else (g2f_latlong = g2f_latlong)
})
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addPolygons(data = county_simplified, weight = 1,
color = "white",
dashArray = '3',
fillOpacity = 0.7,
fillColor = ~pal(zone),
popup = state_popup) %>%
addPolygons(data = state_boundry, weight = 1, color = "grey", fill = NA) %>%
addLegend(pal = pal, value = county_simplified$zone, position = "topright", title = "Zones") %>%
addCircleMarkers(data = g2f(), lng = ~long, lat = ~lat, popup = ~Experiment, radius = 1)
})
}
shinyApp(ui = ui, server = server)
r shiny leaflet
The dataset is not reproducible and unclear. It is hard to do get data from an image. Instead you could provide the output ofdput(head(g2f_latlong))
which is more easy to work.
– msr_003
Nov 8 at 5:17
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a dataset that have the long and lat information, as well as the 'Experiment' info for each long and lat.
I used addCircleMarkers to add markers. And I want to have popup options for each marker. I tried to call "Experiment" at popup, but it gives me errors that it can't find this variable. I am not sure where it went wrong.
Dataset
ui <- fluidPage(
titlePanel("Land Explorer"),
selectInput("year", "Year of G2F", choices = c("2014", "2015", "2016", "All")),
fluidRow(
mainPanel(
tags$style(type = "text/css", "#map {height: calc(100vh - 80px) !important;}"),
leafletOutput("map"), width = "100%", height = 1000)
)
)
server <- function(input, output){
pal <- colorFactor("RdYlGn", county_simplified$zone, reverse = T, na.color = "white")
state_popup <- paste0("<strong>State: </strong>",
county_simplified$region,
"<br><strong>County: </strong>",
county_simplified$subregion)
g2f <- reactive ({
if (input$year == "2014"){
g2f_latlong = g2f_latlong[g2f_latlong$year == 2014, ]
}
else if (input$year == "2015"){
g2f_latlong = g2f_latlong[g2f_latlong$year == 2015, ]
}
else if (input$year == "2016") {
g2f_latlong = g2f_latlong[g2f_latlong$year == 2016, ]
}
else if (input$year == "All"){
g2f_latlong = g2f_latlong
}
else (g2f_latlong = g2f_latlong)
})
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addPolygons(data = county_simplified, weight = 1,
color = "white",
dashArray = '3',
fillOpacity = 0.7,
fillColor = ~pal(zone),
popup = state_popup) %>%
addPolygons(data = state_boundry, weight = 1, color = "grey", fill = NA) %>%
addLegend(pal = pal, value = county_simplified$zone, position = "topright", title = "Zones") %>%
addCircleMarkers(data = g2f(), lng = ~long, lat = ~lat, popup = ~Experiment, radius = 1)
})
}
shinyApp(ui = ui, server = server)
r shiny leaflet
I have a dataset that have the long and lat information, as well as the 'Experiment' info for each long and lat.
I used addCircleMarkers to add markers. And I want to have popup options for each marker. I tried to call "Experiment" at popup, but it gives me errors that it can't find this variable. I am not sure where it went wrong.
Dataset
ui <- fluidPage(
titlePanel("Land Explorer"),
selectInput("year", "Year of G2F", choices = c("2014", "2015", "2016", "All")),
fluidRow(
mainPanel(
tags$style(type = "text/css", "#map {height: calc(100vh - 80px) !important;}"),
leafletOutput("map"), width = "100%", height = 1000)
)
)
server <- function(input, output){
pal <- colorFactor("RdYlGn", county_simplified$zone, reverse = T, na.color = "white")
state_popup <- paste0("<strong>State: </strong>",
county_simplified$region,
"<br><strong>County: </strong>",
county_simplified$subregion)
g2f <- reactive ({
if (input$year == "2014"){
g2f_latlong = g2f_latlong[g2f_latlong$year == 2014, ]
}
else if (input$year == "2015"){
g2f_latlong = g2f_latlong[g2f_latlong$year == 2015, ]
}
else if (input$year == "2016") {
g2f_latlong = g2f_latlong[g2f_latlong$year == 2016, ]
}
else if (input$year == "All"){
g2f_latlong = g2f_latlong
}
else (g2f_latlong = g2f_latlong)
})
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addPolygons(data = county_simplified, weight = 1,
color = "white",
dashArray = '3',
fillOpacity = 0.7,
fillColor = ~pal(zone),
popup = state_popup) %>%
addPolygons(data = state_boundry, weight = 1, color = "grey", fill = NA) %>%
addLegend(pal = pal, value = county_simplified$zone, position = "topright", title = "Zones") %>%
addCircleMarkers(data = g2f(), lng = ~long, lat = ~lat, popup = ~Experiment, radius = 1)
})
}
shinyApp(ui = ui, server = server)
r shiny leaflet
r shiny leaflet
asked Nov 7 at 18:26
Keru Chen
61
61
The dataset is not reproducible and unclear. It is hard to do get data from an image. Instead you could provide the output ofdput(head(g2f_latlong))
which is more easy to work.
– msr_003
Nov 8 at 5:17
add a comment |
The dataset is not reproducible and unclear. It is hard to do get data from an image. Instead you could provide the output ofdput(head(g2f_latlong))
which is more easy to work.
– msr_003
Nov 8 at 5:17
The dataset is not reproducible and unclear. It is hard to do get data from an image. Instead you could provide the output of
dput(head(g2f_latlong))
which is more easy to work.– msr_003
Nov 8 at 5:17
The dataset is not reproducible and unclear. It is hard to do get data from an image. Instead you could provide the output of
dput(head(g2f_latlong))
which is more easy to work.– msr_003
Nov 8 at 5:17
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You are not returning the filtered data from reactive
environment, so your addCircleMarkers
function do not get data to plot on leaflet. Change your reactive
environment as shown below and i hope this solves your issue.
g2f <- reactive({
if (input$year == "2014") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2014, ]
}else if (input$year == "2015") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2015, ]
}else if (input$year == "2016") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2016, ]
}else if (input$year == "All") {
filtered_data <- g2f_latlong
}else {filtered_data <- g2f_latlong}
return(filtered_data)
})
With the limited explanation and data i could only check foraddCircleMarkers
. But you are using ` county_simplified` &state_boundry
data, which are not available to check foraddPolygons
.
– msr_003
Nov 8 at 5:25
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You are not returning the filtered data from reactive
environment, so your addCircleMarkers
function do not get data to plot on leaflet. Change your reactive
environment as shown below and i hope this solves your issue.
g2f <- reactive({
if (input$year == "2014") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2014, ]
}else if (input$year == "2015") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2015, ]
}else if (input$year == "2016") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2016, ]
}else if (input$year == "All") {
filtered_data <- g2f_latlong
}else {filtered_data <- g2f_latlong}
return(filtered_data)
})
With the limited explanation and data i could only check foraddCircleMarkers
. But you are using ` county_simplified` &state_boundry
data, which are not available to check foraddPolygons
.
– msr_003
Nov 8 at 5:25
add a comment |
up vote
0
down vote
You are not returning the filtered data from reactive
environment, so your addCircleMarkers
function do not get data to plot on leaflet. Change your reactive
environment as shown below and i hope this solves your issue.
g2f <- reactive({
if (input$year == "2014") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2014, ]
}else if (input$year == "2015") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2015, ]
}else if (input$year == "2016") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2016, ]
}else if (input$year == "All") {
filtered_data <- g2f_latlong
}else {filtered_data <- g2f_latlong}
return(filtered_data)
})
With the limited explanation and data i could only check foraddCircleMarkers
. But you are using ` county_simplified` &state_boundry
data, which are not available to check foraddPolygons
.
– msr_003
Nov 8 at 5:25
add a comment |
up vote
0
down vote
up vote
0
down vote
You are not returning the filtered data from reactive
environment, so your addCircleMarkers
function do not get data to plot on leaflet. Change your reactive
environment as shown below and i hope this solves your issue.
g2f <- reactive({
if (input$year == "2014") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2014, ]
}else if (input$year == "2015") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2015, ]
}else if (input$year == "2016") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2016, ]
}else if (input$year == "All") {
filtered_data <- g2f_latlong
}else {filtered_data <- g2f_latlong}
return(filtered_data)
})
You are not returning the filtered data from reactive
environment, so your addCircleMarkers
function do not get data to plot on leaflet. Change your reactive
environment as shown below and i hope this solves your issue.
g2f <- reactive({
if (input$year == "2014") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2014, ]
}else if (input$year == "2015") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2015, ]
}else if (input$year == "2016") {
filtered_data <- g2f_latlong[g2f_latlong$year == 2016, ]
}else if (input$year == "All") {
filtered_data <- g2f_latlong
}else {filtered_data <- g2f_latlong}
return(filtered_data)
})
answered Nov 8 at 5:10
msr_003
3671315
3671315
With the limited explanation and data i could only check foraddCircleMarkers
. But you are using ` county_simplified` &state_boundry
data, which are not available to check foraddPolygons
.
– msr_003
Nov 8 at 5:25
add a comment |
With the limited explanation and data i could only check foraddCircleMarkers
. But you are using ` county_simplified` &state_boundry
data, which are not available to check foraddPolygons
.
– msr_003
Nov 8 at 5:25
With the limited explanation and data i could only check for
addCircleMarkers
. But you are using ` county_simplified` & state_boundry
data, which are not available to check for addPolygons
.– msr_003
Nov 8 at 5:25
With the limited explanation and data i could only check for
addCircleMarkers
. But you are using ` county_simplified` & state_boundry
data, which are not available to check for addPolygons
.– msr_003
Nov 8 at 5:25
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195583%2fcant-find-variable-from-a-dataframe-when-try-to-call-in-addcirclemarker-in-r-sh%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The dataset is not reproducible and unclear. It is hard to do get data from an image. Instead you could provide the output of
dput(head(g2f_latlong))
which is more easy to work.– msr_003
Nov 8 at 5:17