Reputation: 1299
I have the following ui.R
library(shiny)
zones <- read.csv("sample_sites.csv", header = TRUE)
zonesnames <- levels(zones$pressure_zone_name)
availablelocations <- zones %>% filter(pressure_zone_name=="Allied Gardens") %>% select(location_description)
# Define UI for application
shinyUI(fluidPage(
# Application title
titlePanel("San Diego Drinking water sample sites"),
# Sidebar
sidebarLayout(
sidebarPanel(
selectInput("zones",
label = "Choose a zone to display",
choices = zonesnames),
selectInput("sampleLocation",
label = "Choose a location_description",
choices = availablelocations)
),
# Show a plot of the selected data
mainPanel(
plotOutput("zonesDataPlot")
)
)
))
And the following server.R
library(shiny)
library(magrittr)
library(dplyr)
zoneData <- read.csv("sample_sites.csv", header = TRUE)
shinyServer(function(input,output,session) {
observe({
availablelocations <- zoneData %>%
filter(pressure_zone_name==input$zones) %>% select(location_description)
updateSelectInput(session, "sampleLocation", choices =
availablelocations)
})
output$zonesDataPlot <- renderPlot({
plotData <- subset(zones, pressure_zone_name==input$zones &
location_description==input$location_description)
})
})
I haven't yet tried to implement the plot, just trying to get the selectInput working.
My data is
structure(list(site_ID = structure(c(135L, 153L, 121L, 5L, 131L,
123L, 40L, 140L, 139L, 104L, 141L, 2L, 48L, 64L, 120L, 137L,
65L, 61L, 81L, 47L, 42L, 70L, 33L, 25L, 31L, 73L, 78L, 55L, 129L,
103L, 38L, 74L, 69L, 109L, 16L, 145L, 6L, 7L, 17L, 132L, 82L,
83L, 60L, 106L, 75L, 113L, 77L, 28L, 37L, 29L, 86L, 63L, 94L,
41L, 20L, 84L, 85L, 136L, 80L, 138L, 26L, 24L, 1L, 87L, 67L,
66L, 88L, 35L, 107L, 13L, 149L, 8L, 9L, 93L, 133L, 14L, 108L,
27L, 105L, 143L, 144L, 146L, 147L, 95L, 102L, 71L, 68L, 148L,
157L, 72L, 57L, 18L, 142L, 111L, 152L, 116L, 119L, 3L, 4L, 15L,
151L, 43L, 56L, 10L, 11L, 30L, 154L, 90L, 92L, 89L, 32L, 19L,
96L, 100L, 101L, 114L, 126L, 79L, 156L, 21L, 97L, 49L, 54L, 22L,
12L, 34L, 150L, 134L, 110L, 23L, 99L, 36L, 58L, 50L, 53L, 155L,
51L, 52L, 59L, 39L, 122L, 76L, 62L, 125L, 112L, 44L, 124L, 117L,
45L, 115L, 98L, 128L, 91L, 130L, 46L, 127L, 118L), .Label = c("128 SYS",
"131 SYS", "132 SYS", "134A SYS", "135 SYS", "138A SYS", "140 SYS",
"144 SYS", "148 SYS", "150 SYS", "151A SYS", "152A SYS", "153 SYS",
"155 SYS", "171 SYS", "173 SYS", "174 SYS", "176 SYS", "177 SYS",
"179 SYS", "182 SYS", "184 SYS", "185 SYS", "200 SYS", "201 SYS",
"204A SYS", "205 SYS", "206 SYS", "207 SYS", "208A SYS", "209 SYS",
"210 SYS", "211 SYS", "212 SYS", "213 SYS", "214 SYS", "215 SYS",
"216 SYS", "218 SYS", "219 SYS", "221 SYS", "222A SYS", "223 SYS",
"224 SYS", "225 SYS", "226 SYS", "229 SYS", "230 SYS", "231 SYS",
"233 SYS", "234A SYS", "235 SYS", "236 SYS", "237 SYS", "239 SYS",
"240 SYS", "241SYS", "242 SYS", "243 SYS", "244 SYS", "245 SYS",
"246 SYS", "247A SYS", "248 SYS", "249A SYS", "250 SYS", "251 SYS",
"252A SYS", "253 SYS", "255 SYS", "256 SYS", "257 SYS", "258 SYS",
"259 SYS", "261 SYS", "262 SYS", "264 SYS", "265 SYS", "268 SYS",
"270A SYS", "273 SYS", "274 SYS", "275 SYS", "276A SYS", "277A SYS",
"278 SYS", "279 SYS", "280 SYS", "281 SYS", "282 SYS", "283 SYS",
"284 SYS", "285 SYS", "286 SYS", "287 SYS", "288 SYS", "289 SYS",
"290 SYS", "291 SYS", "294 SYS", "295 SYS", "299 SYS", "300 SYS",
"301 SYS", "302 SYS", "303A SYS", "304 SYS", "305 SYS", "306 SYS",
"307 SYS", "309 SYS", "313 SYS", "314 SYS ", "315A SYS", "316 SYS",
"317 SYS", "318A SYS", "319 SYS", "320 SYS", "321 SYS", "322 SYS",
"323 SYS", "324 SYS", "325 SYS", "326 SYS", "327 SYS", "328 SYS",
"329 SYS", "330 SYS", "331 SYS", "332 SYS", "333 SYS", "334 SYS",
"336 SYS", "338 SYS", "339 SYS", "341 SYS", "342 SYS", "43 SYS",
"44 SYS", "48 SYS", "49A SYS", "50A SYS", "52 SYS", "53 SYS",
"55A SYS", "57 SYS", "59 SYS", "60 SYS", "63A SYS", "64 SYS",
"65 SYS", "66 SYS", "67 SYS", "68 SYS", "77A SYS", "78A SYS"), class = "factor"),
pressure_zone_name = structure(c(48L, 49L, 101L, 88L, 88L,
38L, 45L, 82L, 83L, 120L, 46L, 72L, 92L, 33L, 73L, 73L, 34L,
29L, 6L, 19L, 128L, 74L, 87L, 20L, 1L, 85L, 131L, 7L, 25L,
30L, 41L, 100L, 54L, 86L, 129L, 130L, 130L, 130L, 130L, 130L,
96L, 59L, 28L, 98L, 102L, 115L, 126L, 22L, 10L, 24L, 8L,
32L, 50L, 51L, 52L, 53L, 80L, 81L, 91L, 77L, 9L, 116L, 117L,
17L, 42L, 40L, 47L, 61L, 15L, 2L, 3L, 3L, 3L, 4L, 5L, 62L,
94L, 37L, 97L, 68L, 68L, 68L, 68L, 95L, 99L, 76L, 43L, 39L,
39L, 78L, 21L, 63L, 64L, 64L, 65L, 65L, 66L, 75L, 75L, 75L,
56L, 56L, 16L, 93L, 93L, 27L, 12L, 13L, 71L, 60L, 105L, 57L,
57L, 57L, 57L, 118L, 67L, 55L, 127L, 127L, 89L, 90L, 14L,
119L, 103L, 103L, 114L, 69L, 107L, 113L, 109L, 125L, 23L,
18L, 18L, 79L, 79L, 84L, 26L, 44L, 121L, 104L, 31L, 106L,
11L, 110L, 110L, 111L, 124L, 35L, 36L, 122L, 58L, 112L, 108L,
123L, 70L), .Label = c("Allied Gardens", "Alvarado (100)",
"Alvarado (181)", "Alvarado (35)", "Alvarado (41)", "Archer",
"Arnold Hills", "Arroyo Sorrento", "Bay Terrace", "Bay View",
"Bernardo Heights", "Bernardo Oaks (51) ", "Bernardo Oaks(41)",
"Bernardo Trails", "Black Mtn Ranch", "Carbrillo Palisades",
"Carmel Country", "Carmel Mall", "Carmel Valley", "Carmel View",
"Carroll Ridge", "Catalina", "Climax", "College Canyon",
"Cornish Hill", "Country Casual", "Del Cerro", "Del Mar Hills",
"Del Mar Terrace", "Dennery Ranch", "Eagle Ridge", "El Camino",
"Floral Terrace", "Glidden", "Golf Course (11)", "Golf Course (5)",
"Hillsborough", "Imperial", "Kearny Mesa", "La Jolla Gardens",
"La Jolla Hermosa", "La Jolla Mesa Vista", "La Jolla Pacifica",
"La Jolla Soledad W", "La Jolla Sores", "La Jolla Towne",
"La Mirage", "Liberty Station", "Lower Del Mar Terrace",
"Lusk Park (16)", "Lusk Park (50)", "Lusk Park (81)", "Lusk Park(24)",
"Mar Villa", "Mercy High", "Mira Mesa", "Miramar ", "Miramar Boosted",
"Mission City", "Monte Verde", "Murphy Canyon", "Normal Heights",
"North City (33)", "North City (412)", "North City (92)",
"North City(48)", "North Village", "Northwest Mesa", "Oaks North",
"Otay Mesa", "OTAY MESA", "Otay Regulated", "Pacific Beach",
"Pacifica", "Paradise Mesa", "Paradise Mesa #2", "Paraduse Hills #1",
"Parkview", "Penasquitos", "Penasquitos Park VW", "Pinnacle Zone",
"Point Loma (20)", "Point Loma (37)", "Pomerado Park", "Prestwick Estates",
"Princess Del Sol", "Princess Gardens", "Principal Downtown",
"Rancho Bernardo (144)", "Rancho Bernardo (229) ", "Rancho Del Sol",
"Rancho Santa Fe", "Redwood Village", "Remington Hills",
"Ridgegate La Jolla", "Ridgegate Reduced", "Riviera Del Sol",
"Riviera Shores", "Robinhood Ridge", "Rodefer", "Rosecrans",
"San Andress", "San Carlos", "San Carlos Estates", "San Carlos Reduced",
"Santa Luz", "Scripps Eastview", "Scripps Hills", "Scripps Mesa",
"Scripps Ranch (229)", "Scripps Ranch (5)", "Scripps Ranch Boosted",
"Scripps Ranch North", "Scripps Valley", "So La Jolla Cliffs",
"So San Diego Resv", "So San Diego Resv (65)", "Soledad Muirlands",
"South Creek", "Stallion Crossing", "Stockwood", "Stonebridge",
"Sycamore Estates", "Sycamore Hills", "Tierrasanta Norte",
"Tierrasanta Sur", "Tierrasnanta", "Torrey Pines", "University Heights (22)",
"University Heights (418)", "Wabash Mesa"), class = "factor"),
pressure_zone_elevation = structure(c(8L, 9L, 10L, 11L, 11L,
12L, 13L, 14L, 14L, 15L, 16L, 16L, 17L, 18L, 19L, 19L, 20L,
21L, 22L, 22L, 22L, 23L, 24L, 25L, 26L, 26L, 26L, 27L, 28L,
29L, 30L, 30L, 31L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 33L,
34L, 35L, 36L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L, 42L, 43L, 44L, 44L, 44L, 45L, 45L,
46L, 46L, 46L, 47L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 49L,
50L, 50L, 51L, 51L, 51L, 51L, 52L, 53L, 54L, 55L, 56L, 56L,
56L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 58L,
58L, 59L, 60L, 60L, 61L, 62L, 62L, 62L, 63L, 64L, 65L, 65L,
65L, 65L, 66L, 67L, 68L, 69L, 69L, 70L, 70L, 71L, 72L, 73L,
73L, 74L, 75L, 76L, 76L, 77L, 78L, 79L, 80L, 80L, 80L, 80L,
80L, 81L, 81L, 81L, 82L, 83L, 84L, 1L, 1L, 1L, 1L, 2L, 3L,
3L, 4L, 5L, 5L, 6L, 7L, 85L), .Label = c("1020", "1050",
"1130", "1135", "1150", "1200", "1250", "175", "196", "225",
"231", "240", "241", "260", "263", "270", "284", "295", "307",
"320", "328", "330", "340", "345", "346", "355", "358", "360",
"365", "370", "378", "390", "425", "430", "435", "440", "447",
"450", "462", "463", "468", "470", "472", "490", "495", "500",
"520", "536", "543", "550", "559", "575", "580", "590", "594",
"600", "610", "625", "635", "645", "656", "680", "685", "692",
"712", "725", "730", "750", "752", "793", "800", "815", "849",
"850", "865", "890", "892", "900", "910", "920", "925", "930",
"940", "950", "N/A"), class = "factor"), connections_count = c(228L,
195L, 237L, 1565L, 1565L, 8L, 498L, 3924L, 1126L, 46L, 1240L,
2426L, 156L, 208L, 8847L, 8847L, 28L, 248L, 32L, 1698L, 170L,
22L, 13L, 540L, 1199L, 34L, 162L, 48L, 31L, 178L, 3100L,
78L, 79L, 2150L, 1864L, 28905L, 28905L, 28905L, 28905L, 28905L,
44L, 122L, 396L, 4L, 134L, 35L, 292L, 4348L, 884L, 93L, 1220L,
1L, 262L, 83L, 3907L, 94L, 885L, 7L, 180L, 1863L, 195L, 423L,
423L, 245L, 261L, 450L, 61L, 29L, 167L, 4106L, 29438L, 29438L,
29438L, 541L, 1464L, 5254L, 251L, 442L, 123L, 33770L, 33770L,
33770L, 33770L, 67L, 221L, 49L, 458L, 4758L, 4758L, 484L,
31L, 98L, 3263L, 3263L, 9700L, 9700L, 320L, 13283L, 13283L,
13283L, 14681L, 14681L, 45L, 9276L, 9276L, 1257L, 2126L,
1824L, 1404L, 652L, 255L, 5834L, 7485L, 14261L, 4830L, 2020L,
205L, 53L, 1485L, 1485L, 3394L, 4557L, 1035L, 538L, 6365L,
6365L, 756L, 21L, 179L, 1850L, 46L, 503L, 1138L, 2379L, 2379L,
3158L, 3164L, 1954L, 162L, 504L, 28L, 603L, 78L, 33L, 1175L,
3723L, 3882L, 96L, 320L, 131L, 36L, 129L, 769L, 829L, 208L,
112L, NA), location_description = structure(c(55L, 156L,
50L, 112L, 21L, 64L, 117L, 157L, 57L, 29L, 124L, 126L, 122L,
51L, 131L, 44L, 84L, 22L, 125L, 123L, 60L, 73L, 90L, 47L,
67L, 96L, 48L, 40L, 93L, 76L, 80L, 61L, 25L, 27L, 149L, 52L,
62L, 66L, 58L, 26L, 133L, 143L, 23L, 34L, 155L, 98L, 5L,
6L, 114L, 78L, 113L, 101L, 120L, 77L, 24L, 75L, 110L, 14L,
148L, 56L, 54L, 2L, 129L, 7L, 81L, 92L, 87L, 65L, 32L, 79L,
106L, 121L, 154L, 135L, 82L, 118L, 72L, 46L, 68L, 53L, 139L,
74L, 134L, 150L, 119L, 43L, 145L, 137L, 83L, 111L, 102L,
104L, 136L, 63L, 127L, 20L, 19L, 70L, 132L, 86L, 8L, 95L,
59L, 107L, 71L, 115L, 147L, 45L, 141L, 89L, 116L, 18L, 130L,
17L, 10L, 1L, 38L, 103L, 146L, 85L, 128L, 152L, 42L, 16L,
99L, 151L, 105L, 41L, 11L, 9L, 140L, 69L, 91L, 15L, 37L,
144L, 31L, 39L, 100L, 49L, 12L, 88L, 94L, 97L, 13L, 3L, 142L,
109L, 4L, 28L, 30L, 33L, 153L, 108L, 138L, 35L, 36L), .Label = c(" Across from 5494 Soledad Rd ",
" Otay Mesa Rd/Beyer Blvd", "10054 Avenida Magnifica @ Public School",
"10314 Rue Chantemar", "10460 Viacha Dr; Sample Stanchion",
"1055 Catalina Blvd; @ Fire Station Sample Stanchion", "10885 Cloverhurst ",
"11168 Avenida Del Gato & Zapata", "11198 Ivy Hill Dr", "11305 Affinity Ct",
"11455 East Ridge Place", "11469 Stonecroft Terrace", "11602 Calle Paracho",
"11911 Carmel Creek Rd", "12119 World Trade Dr @ a Fire Station",
"12170 Springhurst Dr", "12195 Branicole St", "12350 Black Mountain Rd (Next the Rec Building)",
"12501 La Tortola Dr", "12608 Spindle Top Dr", "1277 G St",
"12935 Via Latina; Sample Stanchion", "13051 Portofino Dr; Sample Stanchion",
"13075 Hartfield Ave @ Del Mar Heights", "13200 Blk Caminito Mar Villa",
"1329 Gertrude St; Sample Stanchion", "1332 Kenalan Dr",
"13705 Shoal Summit Dr", "13782 Rosecroft Way", "14254 Breezeway Place Silver sample stanchion",
"14300 Block Cuca St. ", "14462 Garden Trail", "14644 1/2 Old Creek Rd",
"1469 Riviera Shores St ", "14800 Stone Bridge Pkwy", "1500 Wueste Rd, Chula Vista CA",
"15022 Avenida Venusto", "15625 New Park Terrace", "15855 Turtleback Rd",
"1761 Petra Dr", "17696 Montero Rd", "17910 Avenida Cordillera",
"1808 Sea Star Way (Keyless Hose Bib on the enclosed backflow Preventer Cage)",
"1840 Quiveira Way", "18402 West Bernardo Dr. Stantion at a community Park",
"1848 Manzana Way; Sample Stanchion", "1880 Smythe Ave; Sample Stanchion",
"2023 Haller St.", "2110 Via Casa Alta @ a Fire Station",
"2305 1/2 Historic Decatur Rd", "2360 Beryl St; Sample Stanchion",
"2433 Denver St; Public School/Sample Stanchion", "2693 Melbourne Dr.",
"2787 Alta View Drive", "2850 Wasp Way", "2883 Keen Dr & Parkside Ave",
"300 BLK of Rosecrans Sample Stanchion", "3250 Camino Del Rio North; Sample Stanchion",
"3387 Kearny Villa Lane", "3550 Dunhill St", "3945 Alameda Dr; Sample Box",
"4202 N.Harbor Dr & W.Spanish Landing Dr.", "4274 Campus Point Ct",
"4393 Redworks Drwy (Behind Health Care Training)", "4455 Murphy Canyon Rd; Sample Stanchion",
"45th St/Imperial Ave; Sample Stanchion", "4605 Vandever Ave; (W.End or Public Park)",
"4610 Pacific Riviera Way", "4711 Seda Dr; (Between Via Dominique & Renovo Way)",
"480 S. Meadowbrook Dr", "4929 Catoctin Dr Sample Stanchion",
"4948 1/2 Carbine way", "4949 Pacifica Dr; Sample Box", "5183 Arvinels Ave.",
"5285 Setting Sun Way", "5368 Topsail Dr", "54551/2 Oberlin Dr",
"5485 Adobe Falls Rd; Sample Stanchion", "5552 Gala Avenue",
"5790 Chelsea Ave", "5840 Ravenswood Rd;", "6070 Division St",
"6200 Calle Mariselda", "6429 Glidden St; Sample Stanchion",
"6475 Antigua", "6541 Broadway", "6542 Reflection Dr", "6669 Linda Lane",
"6831 Monte Verde Dr", "7228 Wembley St", "7260 Barker Way",
"7474 Charmant Dr. Sample Stanchion", "775 Cornish Dr", "7928 Wing Span Dr",
"8441 New Salem St @ Fire Station", "8455 Westway Dr", "8555 1/2 Run of the Knolls Rd",
"8555 Ruette Monte Carlo", "8571 Highwood Drive", "8709 Lake Athabaska Way",
"9151 Rehco Rd; Sample Stanchion", "9440 Carroll Park Dr",
"9604 Babauta Rd", "9896 Olson Dr; ", "9930 Aviary Drive",
"9th Ave & University Ave @ Fire Station", "Acorn St & 62nd S t@ Fire Station",
"Across from 11705 Semillon Blvd.", "Across from 11810 Trail Crest Dr",
"Across from 12241 Camino Del Sur", "Across from 1565 Calle De Cinco",
"Across from 1782 Newton Ave ", "Across from 3750 Torrey View Ct ",
"Across from 5105 Soledad Rd.", "Across from 6236 Wenrich Dr., in front of community park",
"Across from 6619 Cibola Rd (Infront of a Park)", "Across from 8415 El Paseo Grande",
"Adams & Marlborough", "Avenida De Las Vistas / Vista San Rafael",
"Between Reedley and Drakewood on open space area", "Brookline & Date",
"Camto Mar De Plata & Camto Fortaleza", "Carmel Park Dr/Del Mar Glen; Public School",
"Coast BL South/Eads Ave; Sample Stanchion", "Dawes St & Archer St. (SE corner)",
"East Park Ave/San Ysidro Blvd; Sample Stanchion", "El Amigo Rd & Durango Dr",
"Escala Dr & Camberwell Lane ", "Firethorn St/Palm Ave; Sample Stanchion",
"Greenberg Way & Ganso Corte @ backflow preventer", "Haines St @ Felspar St.",
"Herrick St & 65th St", "Hillpointe Row & Carriage Dale Row",
"Idlewild way & Hidalgo Ave; @ Public School", "Jamacha Rd and 68th St. (SE corner near playground of Boys Club)",
"John J. Hopkins & General Atomic", "La Cuenta Dr & Tierrasanta Blvd @ Fire station",
"Meadowdale Lane & Walnutdale St", "MT. Abernathy Ave & Chateau Dr @ Library",
"Nob Hill Condos (10815)", "Ocean View Hills Pkwy and Sea Drift Dr.",
"Old Creek Rd and Whispering Ridge", "Old Quarry Rd @ Questor Pl",
"Oviedo st & Black Mtn Rd", "Pacifica Dr and Soledad Mtn Road",
"Palabra Circle", "Pomerado Rd & Grandee Place", "Rancho Del Sol Way & Rancho Del Azalea Way",
"Rancho Hills Dr/Reo Dr; @ Library/Sample Stanchion", "Ridgegate Row & Abbotswoods",
"Rondel CT & Tuxedo Rd; @ Public Park", "Salmon River & Fairgrove Ln @ the Library",
"Scripps Ranch wy & Spencerport (SW corner)", "Upas & Richmond",
"Via Campestre & Camto Punta Arenas ", "Via Cortina/Via Aprilia Sample Stanchion",
"Voltaire St/Ebers St; @ a Fire Station Sample Stanchion"
), class = "factor"), latitude = c(32.72865278, 32.93433056,
32.73386667, 32.70124722, 32.71269722, 32.70344444, 32.85918889,
32.74886667, 32.70785556, 32.9694, 32.84578333, 32.55273333,
32.98311111, 32.8089, 32.80038611, 32.75951667, 32.77602778,
32.93468056, 32.81170556, 32.940875, 32.90312222, 32.81121111,
32.80205833, 32.56377222, 32.78762222, 32.859875, 32.72652222,
32.72427778, 32.7208, 32.588625, 32.81735556, 32.748825,
32.94041944, 32.57251667, 32.67250556, 32.7875, 32.72874444,
32.70399167, 32.77695833, 32.77258889, 32.831775, 32.78661111,
32.93649444, 32.57158056, 32.98451667, 32.86192778, 32.81,
32.72560556, 32.81157778, 32.78141389, 32.92097222, 32.88936111,
32.96632778, 32.89150278, 32.95636389, 32.90968611, 32.94198611,
32.93474167, 32.96488889, 32.67034444, 32.67575, 32.55910278,
32.58387778, 32.93180556, 32.81846111, 32.86541389, 32.79296944,
32.82497778, 32.98470556, 32.79987222, 32.74857222, 32.72351944,
32.74107222, 32.71044444, 32.69445833, 32.76293611, 32.56473056,
32.68731944, 32.57033889, 32.79343056, 32.82235278, 32.84008333,
32.83207778, 32.83044444, 32.58345556, 32.68537778, 32.82041944,
32.82057222, 32.83556389, 32.81933611, 32.88749167, 32.88583611,
32.89457222, 32.88754444, 32.95062222, 32.95101944, 32.945825,
32.697675, 32.71114722, 32.71578333, 32.92427222, 32.91565556,
32.80561389, 32.76067222, 32.76760278, 32.78936667, 33.01172778,
33.01764722, 32.57711944, 32.81230556, 32.80676944, 32.94228611,
32.96903889, 32.94007222, 32.92258889, 32.81903611, 33.01915556,
32.93796389, 32.82417222, 32.83672778, 33.04518056, 32.95783611,
33.04235, 32.93946111, 32.80863056, 32.80907222, 32.90321667,
33.02531944, 32.92674444, 32.93612778, 32.91596389, 32.82606667,
32.81323889, 32.98314167, 32.99166944, 32.96886667, 32.97400278,
33.00532222, 32.79916111, 32.83901667, 32.92419722, 32.78458889,
32.80684722, 32.99057222, 33.00098333, 32.90753889, 32.92449167,
32.93194444, 32.9062, 32.96578333, 32.97615833, 32.92568056,
32.9238, 32.92226944, 32.907125, 32.92566389, 32.60828611
), longitude = c(-117.222875, -117.2526889, -117.2170722,
-117.1479972, -117.1530083, -117.1019611, -117.2554722, -117.2417444,
-117.238925, -117.2379722, -117.2776861, -117.0441611, -117.2463472,
-117.2286806, -117.2430083, -117.2335972, -117.1790361, -117.2479056,
-117.2540889, -117.2294861, -117.2293306, -117.2225917, -117.0817972,
-117.0494694, -117.0956, -117.2499944, -117.1143833, -117.1183889,
-117.2538778, -117.0149556, -117.2726139, -117.1837944, -117.25775,
-117.0489528, -117.0612583, -117.2036889, -117.2105111, -117.0980861,
-117.1255056, -117.2017528, -117.23455, -117.1288722, -117.243575,
-117.0377194, -117.2441333, -117.2500806, -117.0970944, -117.2445722,
-117.2400694, -117.0809833, -117.2336639, -117.172325, -117.2141306,
-117.1996917, -117.2300222, -117.2005444, -117.151625, -117.2265778,
-117.1783417, -117.0480139, -117.0431056, -117.0409056, -117.0394861,
-117.2016528, -117.2635389, -117.2282056, -117.10775, -117.119125,
-117.1638333, -117.0699167, -117.1564556, -117.0914444, -117.1511,
-117.0510722, -117.0677444, -117.1063861, -117.0332083, -117.0237556,
-117.03535, -117.1249222, -117.1751444, -117.1750583, -117.2207472,
-117.238125, -117.0141111, -117.0560667, -117.2334111, -117.0986222,
-117.096575, -117.2471917, -117.1740917, -117.1949556, -117.23975,
-117.2238417, -117.2531528, -117.1362083, -117.1157, -117.0260417,
-117.0579806, -117.0570111, -117.1482222, -117.1421389, -117.1534833,
-117.0635778, -117.05915, -117.0681972, -117.0601222, -117.0737611,
-117.0230361, -117.0481472, -117.0543778, -117.1300889, -117.13665,
-117.1162444, -117.1120917, -117.2408944, -117.1454222, -117.1209444,
-117.0796167, -117.0904083, -117.0638194, -117.1218611, -117.0514444,
-117.07415, -117.0137722, -117.0460056, -117.1009028, -117.0527139,
-117.090625, -117.0906389, -117.1088111, -117.0780972, -117.0177694,
-117.0736861, -117.0678139, -117.1280722, -117.0958806, -117.08775,
-117.0100583, -117.2504306, -117.0419917, -117.0528667, -117.02845,
-117.1361972, -117.0791806, -117.0841611, -117.0316556, -117.1046278,
-117.0649528, -117.0762556, -117.0776639, -117.0257833, -117.0997528,
-117.07655, -117.0615139, -117.0201, -116.9323417), frequency_sampled = structure(c(3L,
3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L,
2L, 3L, 2L, 3L, 3L, 2L, 2L, 3L, 3L, 2L, 3L, 2L, 2L, 3L, 3L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 3L, 2L,
3L, 3L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 2L,
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L,
3L, 3L, 3L, 3L, 3L, 1L), .Label = c("Daily", "Monthly", "Weekly"
), class = "factor")), .Names = c("site_ID", "pressure_zone_name",
"pressure_zone_elevation", "connections_count", "location_description",
"latitude", "longitude", "frequency_sampled"), class = "data.frame", row.names = c(NA,
-157L))
The call to updateSelectInput is there so that the selectInput only has the choices associated with the currently selected zone. It works fine if I select a zone that has more than one location. But if I choose a zone with only one location, which is the majority of the zones, I get a warning in the console that says
Warning in is.na(e2) :
is.na() applied to non-(list or vector) of type 'NULL'
And my second selectInput has once choice that says "location_description"
Not sure where I'm going wrong....
Upvotes: 0
Views: 862
Reputation: 2611
Typically when you use observe
in shiny
you need to do the following things:
You could for example do the following:
observe({
if(length( input$zones ) == 0 ) return()
...
Something like the above allows to avoid running the code if the selectInput
hasn't been selected. You could also pre-select a value (but this is not in your code).
This is a somewhat more advanced concept. If you start your processing with a certain value you want to make sure than it doesn't change midway. You would need to wrap your code in isolate({ your_code })
.
To actually address all of the above issues (and more!), shiny now has the observeEvent
(and eventReactive
) function, that rolls all of the above in one.
This is an extract from shiny reference manual:
observeEvent(eventExpr, handlerExpr, event.env = parent.frame(),
event.quoted = FALSE, handler.env = parent.frame(),
handler.quoted = FALSE, label = NULL, suspended = FALSE, priority = 0,
domain = getDefaultReactiveDomain(), autoDestroy = TRUE,
ignoreNULL = TRUE, ignoreInit = FALSE, once = FALSE)
So, in your case this would become:
observeEvent(input$zones, {
availablelocations <- zoneData %>%
filter(pressure_zone_name==input$zones) %>% select(location_description)
updateSelectInput(session, "sampleLocation", choices =
availablelocations)
})
For example, you can see that the parameter ignoreNULL = TRUE
will prevent the observe to run is course if input$zones
is NULL. Moreover, all the code within {}
is naturally wrapped under an implicit isolate
.
The above should resolve your issue, but unfortunately I didn't manage to test your code (couldn't access the data simply), so if you see that the error persist, please let me know where to find data similar to yours and I'll make sure to post a full functioning version.
Upvotes: 1
Reputation: 7694
You do not have any input called input$location_description
It should be
plotData <- subset(zones, pressure_zone_name==input$zones & location_description==input$sampleLocation)
instead of
plotData <- subset(zones, pressure_zone_name==input$zones &
location_description==input$location_description)
EDIT
Sorry for missing out the main point of the question.Since availablelocations
is a data.frame
your updateSelectInput
should be as follows :
updateSelectInput(session, "sampleLocation", choices = availablelocations[,1])
Hope it helps!
Upvotes: 0