avinax
avinax

Reputation: 127

ERROR: argument "mainPanel" is missing, with no default

I am trying to run the below Shiny App but getting the "ERROR: argument "mainPanel" is missing, with no default" message even when I tried all the solutions available on web. Please help me in finding the error and rectifying it. Thanks in advance.

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)

Upvotes: 2

Views: 3307

Answers (1)

DeanAttali
DeanAttali

Reputation: 26323

Look at the documentation for shiny::sidebarLayout(). It requires a sidebarPanel and a mainPanel. You're only providing a sidebar panel to your sidebar layouts. You need to add a main panel, even if it's empty

Upvotes: 2

Related Questions