我想制作一个闪亮的应用程序,在其中可以从选择下拉框中选择要可视化的不同图层。我尝试了以下代码,但仍然不确定为什么会收到错误消息?任何帮助表示赞赏。它打算具有不同的节律。
ui <- fluidPage(
titlePanel("The Montreal Sustainability Dashboard"),
sidebarLayout(position = "right",
sidebarPanel(
h2("Mobility and Transportation"),
navlistPanel(
"Result",
tabPanel("GHG"),
tabPanel("Calories")
),
selectInput("select_1", label = h5("Choose Base Map"),
choices = c("OSM", "Toner", "Toner Lite"),
selected = "OSM"
),
selectInput("select_2",
label = h5("Choose Mode of Transport"),
choices = c("Cycling","Walking","Drive", "Transit"),
selected = "Cycling"
),
img(src = "MSSI.png", height = 100, width = 500)
),
#-------------------------------------------------------------------------------------------------------------
#define main visualisation part
mainPanel(
p("Sustainability and resiliency issues are increasingly at the forefront of discussions and decisions at all levels of municipal governance and decision-making.
Our team has risen to the challenge by creating the Montreal Sustainability Dashboard, an inclusive and interactive visual platform designed to track, understand and respond to how urban environment impacts upon sustainability.
The dashboard responds to the motivation to develop a tool that is democratic, open, relevant, and accessible to the Montreal community, incorporating the experiences of Montrealers across socioeconomic statuses to include and represent all of its inhabitants and institutions. The dashboard will increase awareness surrounding issues of sustainability and resilience for citizens and organizations in Montreal, incentivize behaviour change, and provide the technical tools and platform to achieve long-term sustainability goals. The Montreal Sustainability Dashboard is funded by the McGill Sustainability Systems Initiative (MSSI). For more info visit",
a("MSSI Homepage.", href = "https://www.mcgill.ca/mssi/"),
plotOutput("map1",width="100%", height=800)
))))
#--------------------------------------------------------------------------------------------------------------
# Define server logic
server <- function(input, output,session){
output$map1 <- renderPlot({
data1<- switch(input$select_2,
"Cycling"=addPolygons(data = CT, weight = 1, fillColor = ~ pal(FM_Bicyc), color = ~pal(FM_Bicyc), fillOpacity = 0.),
"Walking"=addPolygons(data = CT, weight = 1, fillColor = ~ pal(FM_Bicyc), color = ~pal(FM_Bicyc), fillOpacity = 0.),
"Drive"=addPolygons(data = CT, weight = 1, fillColor = ~ pal(FM_Bicyc), color = ~pal(FM_Bicyc), fillOpacity = 0.),
"Transit"=addPolygons(data = CT, weight = 1, fillColor = ~ pal(FM_Bicyc), color = ~pal(FM_Bicyc), fillOpacity = 0.)
)
# width = "auto", height = "auto"
# height = function() {
session$clientData$output_map1_width
#quartz(title="density", height = 400, width = 400)
map1
})
}
# leaflet(CT) %>%
#setView(lng = -73.5673 , lat = 45.5017, zoom = 10) %>%
#addWMSTiles(
#"https://maps.geogratis.gc.ca/wms/elevation_en?",
#layers = "cdem.color-shaded-relief",
#options = WMSTileOptions(format = "image/png", transparent = TRUE),
# attribution = "CDEM (Canadian Digital Elevation Model)")%>%
#addTiles() %>% addProviderTiles(providers$Stamen.Toner)
#addPolygons(data = CT, weight = 1, fillColor = ~ pal(FM_Bicyc), color = ~pal(FM_Bicyc), fillOpacity = 0.)
#addPolygons(data = data_subset, weight = 1, color = "blue", fillOpacity = 0.) #%>%
#addPolylines(data = piste, weight = 3, fillOpacity = 1) %>%
#addLegend(pal=pal, values = ~FM_Bicyc, title="Cycling",group='circles1', position='topright') %>%
#addLegend(pal=pal, values = ~FM_Bicyc, title="Piste", group='circles2', position='topright') %>%
#addLayersControl(baseGroups = c('circles1', 'circles2'))
# Run the app ----
shinyApp(ui = ui, server = server, options = list(height = 1400, width=2800))
现在,我仅使用select_2作为输入,但后来我想对每种类型的数据使用其他输入。