【问题标题】:ERROR: argument "mainPanel" is missing, with no default错误:缺少参数“mainPanel”,没有默认值
【发布时间】:2016-06-08 20:54:54
【问题描述】:

我正在尝试运行下面的 Shiny 应用程序,但即使我尝试了 Web 上可用的所有解决方案,也会收到“错误:参数“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)

【问题讨论】:

  • sidebarLayout 需要一个主面板,你的代码应该是sidebarLayout(sidebarPanel(whatever is in the sidebar), mainPanel(whatever is in the main panel))

标签: r rstudio shiny shinydashboard


【解决方案1】:

查看shiny::sidebarLayout() 的文档。它需要sidebarPanelmainPanel。您只是为侧边栏布局提供侧边栏面板。你需要添加一个主面板,即使它是空的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-10
    • 2017-12-09
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多