我正在尝试运行下面的Shiny App但是得到了#34; ERROR:参数" mainPanel"缺少,没有默认"即使我尝试了网上提供的所有解决方案,也会发出消息请帮我找出错误并纠正错误。提前谢谢。
library(shiny)
library(shinydashboard)
library(leaflet)
library(DT)
library(dplyr)
smartcities <- read.csv("smartcities.csv")
smartcities$State.UT <- as.character(smartcities$State.UT)
smartcities$Status <- as.character(smartcities$Status)
ui <- navbarPage(
headerPanel("Smart Cities Mission"),
tabPanel(tags$h2(tags$b("About Smart Cities Program")), sidebarLayout(sidebarPanel(mainPanel(htmlOutput("about"))))),
tabPanel(tags$h2(tags$b("Selection Process")), sidebarLayout(sidebarPanel(mainPanel(imageOutput("smartimage"))))),
tabPanel(tags$h2(tags$b("Map")), sidebarLayout(sidebarPanel(selectInput("states", selected = "All", label = tags$h2("State"),
choices = c("All", sort(smartcities$State.UT))), radioButtons("shortlisted", selected = "Round One(97)", tags$h2("List of Smart Cities"), c("Round One(97)" = "all", "Selected Cities(Top 20)" = "selected", "On Fast Track Upgrade(23)" = "upgrade", "Round Two(54)" = "two")), mainPanel(leafletOutput("map", height = 635))))),
tabPanel(tags$h2(tags$b("Table")), sidebarLayout(sidebarPanel(selectInput("states", selected = "All", label = tags$h2("State"),
choices = c("All", sort(smartcities$State.UT))), radioButtons("shortlisted", selected = "Round One(97)", tags$h2("List of Smart Cities"), c("Round One(97)" = "all", "Selected Cities(Top 20)" = "selected", "On Fast Track Upgrade(23)" = "upgrade", "Round Two(54)" = "two")), mainPanel(dataTableOutput("table")))))
)
server <- function(input, output) {
output1 <- reactive({
a <- filter(smartcities, State.UT == input$states, Status == input$shortlisted)
a
})
output2 <- reactive({
b <- filter(smartcities, State.UT == input$states, All == "all")
b
})
output3 <- reactive({
c <- filter(smartcities, Status == input$shortlisted)
c
})
output$map <- renderLeaflet(
if(input$shortlisted == "all" & input$states != "All")(
leaflet(data = output2()) %>% setView(lng = 80, lat = 20, zoom = 5) %>% addTiles() %>% addMarkers(~Longitude, ~Latitude, popup = ~paste(sep = "<br/>", paste(tags$b("City:"), City), paste(tags$b("Population:"), Population), paste(tags$b("Score:"), Score))))
else(
if(input$shortlisted == "all" & input$states == "All")
(leaflet(data = smartcities) %>% setView(lng = 80, lat = 20, zoom = 5) %>% addTiles() %>% addMarkers(~Longitude, ~Latitude, popup = ~paste(sep = "<br/>", paste(tags$b("City:"), City), paste(tags$b("Population:"), Population), paste(tags$b("Score:"), Score))))
else(
if(input$shortlisted != "all" & input$states == "All")
(leaflet(data = output3()) %>% setView(lng = 80, lat = 20, zoom = 5) %>% addTiles() %>% addMarkers(~Longitude, ~Latitude, popup = ~paste(sep = "<br/>", paste(tags$b("City:"), City), paste(tags$b("Population:"), Population), paste(tags$b("Score:"), Score))))
else(
leaflet(data = output1()) %>% setView(lng = 80, lat = 20, zoom = 5) %>% addTiles() %>% addMarkers(~Longitude, ~Latitude, popup = ~paste(sep = "<br/>", paste(tags$b("City:"), City), paste(tags$b("Population:"), Population), paste(tags$b("Score:"), Score))))
)))
output$table <- renderDataTable(
if(input$shortlisted == "all" & input$states != "All")(datatable(output2()[c("Rank", "State.UT", "City", "Score", "Population")], options = list(columnDefs = list(list(className = 'dt-center', targets = c(1:5))), pageLength = 15, lengthMenu = c(10, 15))))
else(
if(input$shortlisted == "all" & input$states == "All")
(datatable(smartcities[c("Rank", "State.UT", "City", "Score", "Population")], options = list(columnDefs = list(list(className = 'dt-center', targets = c(1:5))), pageLength = 15, lengthMenu = c(10, 15))))
else(
if(input$shortlisted != "all" & input$states == "All")
(datatable(output3()[c("Rank", "State.UT", "City", "Score", "Population")], options = list(columnDefs = list(list(className = 'dt-center', targets = c(1:5))), pageLength = 15, lengthMenu = c(10, 15))))
else(
(datatable(output1()[c("Rank", "State.UT", "City", "Score", "Population")], options = list(columnDefs = list(list(className = 'dt-center', targets = c(1:5))), pageLength = 15, lengthMenu = c(10, 15))))
))))
output$smartimage <- renderImage(
return(list(src = "Selection.PNG",
contentType = 'image/png',
width = 630,
height = 640)),
deleteFile = FALSE
)
output$about <- renderUI(
tags$div(
tags$h3(tags$p("Smart Cities Mission is an urban renewal and retrofitting program by the Government of India with a mission to develop 100 cities all over the country making them citizen friendly and sustainable. The Union Ministry of Urban Development is responsible for implementing the mission in collaboration with the state governments of the respective cities. The government of India under Prime Minister Narendra Modi has a vision of developing 100 smart cities as satellite towns of larger cities and by modernizing the existing mid-sized cities."),
tags$br(),
tags$p("The 100 potential smart cities were nominated by all the states and union territories based on Stage 1 criteria, prepared smart city plans which were evaluated in stage 2 of the competition for prioritizing cities for financing. In the first round of this stage, 20 top scorers were chosen for financing during 2015-16. The remaining will be asked to make up the deficiencies identified by the Apex Committee in the Ministry of Urban Development for participation in the next two rounds of competition. 40 cities each will be selected for financing during the next rounds of competition.")),
tags$br(),
tags$br(),
tags$a(target="_blank", href="https://en.wikipedia.org/wiki/Smart_Cities_Mission", tags$h4(tags$b("Source: Wikipedia")))
)
)
}
shinyApp(ui, server)
答案 0 :(得分:2)
查看shiny::sidebarLayout()
的文档。它需要sidebarPanel
和mainPanel
。您只需为侧边栏布局提供侧边栏面板。你需要添加一个主面板,即使它是空的