Open lindaalvarez opened 6 months ago
So I just realized that a map shows up in my lower left corner but does not showcase the information I am trying to relay.
@lindaalvarez
I cannot see the rest of your code, but it looks like you are missing:
Outputs
-------------------------------------
### Traffic Accidents By Day and Time
Go back through the code and you will notice that before each code chunk with renderLeaflet you will find this text. This is telling shiny that the subsequent code chunk is the output and the title is Traffic Accidents By Day and Time. Without this, R thinks that you are still building this on the text before the earlier code chunk:
Traffic Accidents By Day and Time
=====================================
Inputs {.sidebar}
-------------------------------------
This is for the sidebar and explains why you are getting a map in your sidebar.
Okay, I will go ahead and keep working on it and let you know if I keep running into issues. Thank you for taking your time to look at this! @JasonSills
This is what my site is looking like as of right now. I was able to fix that error but now my code is not showing the appropriate dots and markers @JasonSills
Additional Conditions {data-orientation=rows} =====================================
Driver Characteristics
radioButtons(inputId = "Weather",
label = h4("Weather on Day of Accident"),
choices = c("Sunny",
"Cloudy",
"Rain"),
selected = "Cloudy")
selectizeInput(inputId = "Lightcondition",
label = h4("Time of Day"),
choices = c("Morning",
"Afternoon",
"Evening"),
selected = "Morning")
selectInput(inputId = "d1gender",
label = h4("Driver 1 Gender"),
choices = c("Male",
"Female",
"Unknown"),
selected = "Male")
selectInput(inputId = "d2gender",
label = h4("Driver 2 Gender"),
choices = c("Male",
"Female",
"Unknown"),
selected = "Male")
radioButtons(inputId = "SurfaceCondition",
label = h4("Street Condition"),
choices = c("No Pot Holes",
"Pot Holes",
"Unknown"),
selected = "No Pot Holes")
radioButtons(inputId = "d1pedcy",
label = h4("Driver 1 Transportation"),
choices = c("Driver",
"Pedalcyclist",
"Pedestrian"),
selected = "Driver")
radioButtons(inputId = "d2pedcy",
label = h4("Driver 2 Transportation"),
choices = c("Driver",
"Pedalcyclist",
"Pedestrian"),
selected = "Driver")
renderLeaflet({
d10 <- dat %>%
filter(Weather >= input$weather.of.day,
Lightcondition <= input$condition.light,
SurfaceCondition <= input$surface.condition,
Gender_Drv1 %in% input$driver.1.gender,
Unittype_One %in% input$driver.1.pedcy )
d10$col.vec <- ifelse(test = d10$nohurt,
yes = "gray20",
no = ifelse(test = d10$inj,
yes = "steelblue",
no = "darkorange"))
point.size <- d10$Totalinjuries + d10$Totalfatalities
crash.details <- paste0("Time: ", d10$DateTime, "<br>",
"Total Fatalities: ", d10$Totalfatalities, "<br>",
"Total Injuries: ", d10$Totalinjuries, "<br>",
"Weather", d10$Weather, "<br>",
"Light Condition", d10$Lightcondition, "<br>",
"SurfaceCondition", d10$SurfaceCondition, "<br>",
"Collision type: ", d10$Collisionmanner)
tempe <- leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
setView(lng = -111.9278,
lat = 33.39951,
zoom = 13)
addCircles(tempe,
lng = d10$Longitude,
lat = d10$Latitude,
fillColor = d10$col.vec,
fillOpacity = 0.5,
stroke = FALSE,
radius = 50 * (1 + 0.33 * point.size),
popup = crash.details)
})
This is the complete code for that "tab". If you had a second to look into this and let me know where I am going wrong I would greatly appreciate it. Thank you for your time @JasonSills
@lindaalvarez
Without seeing the rest of your code, what has me wondering is this portion of the code:
d10 <- dat %>%
filter(Weather >= input$weather.of.day,
Lightcondition <= input$condition.light,
SurfaceCondition <= input$surface.condition,
Gender_Drv1 %in% input$driver.1.gender,
Unittype_One %in% input$driver.1.pedcy )
Have you tried substituting <= and >= with %in%?
Also, try reversing your inputs:
d10 <- dat %>%
filter(Weather %in% input$Weather,
Lightcondition %in% input$Lightcondition,
SurfaceCondition <= input$SurfaceCondition,
Gender_Drv1 %in% input$driver.1.gender,
Unittype_One %in% input$driver.1.pedcy )
Again, I'm not seeing the rest of your code, but your inputs you have the terms used in the section I rewrote. For example, in this section of code:
radioButtons(inputId = "Weather",
label = h4("Weather on Day of Accident"),
choices = c("Sunny",
"Cloudy",
"Rain"),
selected = "Cloudy")
inputID = "Weather". This is your input$ for your output section.
okay I will go ahead and work on that, I will let you know if I am not able to fix this. thank you again!
I was able to figure out where I went wrong @JasonSills - First I was not using the correct terms for the data set and secondly I was not writing my radio buttons and select input correctly. This is a sample of my correct code!
radioButtons(inputId = "Weather", label = h4("Weather"), choices = c("Clear", "Cloudy", "Rain", "Blowing Sand Soil Dirt", "Fog Smog Smoke"), selected = c("Clear"), inline = TRUE)
selectInput(inputId = "LightCondition", label = h4("Light Conditions"), choices = c("Daylight", "Dark Lighted", "Dusk", "Dawn", "Dark Not Lighted"), selected = "Daylight")
@JasonSills
Hello, after successfully creating two new tabs with unique information, I am unable to successfully create the map that goes with the information. It is able to run but when I do so, there is no map. I have attached a screenshot of what my browser looks like as well as the code that I am using when attempting to create the map. I would greatly appreciate some guidance. Thank you.