1

I have a problem with error:

argument "mainPanel" is missing, with no default

I have search forum for similar problems, but I am beginner, so something trivial could be wrong.

The mainPanel is not missing also, commas are correct. Do you have any suggestions?

The csv files are available using this link: https://ufile.io/wknza

Please see code:

library(shiny)
library(fmsb)
library(ggplot2)

nba2 = read.csv("headerlivingconditionsPos.csv", header = TRUE, sep = ",")
nba = read.csv("livingconditions.csv", header = TRUE, sep = ",")
header = read.csv("headerlivingconditions.csv", header = TRUE, sep = ",")

nbaSelectAttributes = nba2
nbaSelectAttributes$COUNTRIES <- NULL
nbaSelectAttributes$TEAM <- NULL
nba2$X <- NULL
attributes <- attributes(nbaSelectAttributes)$names
countriesName = attributes(nba$COUNTRIES)$levels
teams = attributes(nba$TEAM)$levels

ui <- fluidPage(

  titlePanel("NBA Analysis Application"),

  navlistPanel(
    "Menu",
    tabPanel("COUNTRIES Comparison",
             sidebarLayout(
               sidebarPanel(
                 selectInput("country1", "Choose the first country:",
                             choices = countriesName),
                 selectInput("country2", "Choose the second contry:",
                             choices = countriesName),
                 column(12, 
                        checkboxGroupInput("checkGroup", 
                                           h3("Choose the stats that you want to compare (at least 3):"), 
                                           choices = list("Housing" = "HOUSING", 
                                                          "Income" = "INCOME", 
                                                          "Jobs" = "JOBS",
                                                          "Community" = "COMMUNITY",
                                                          "Education" = "EDUCATION",
                                                          "Environment" = "ENVIRONMENT",
                                                          "Civic Engagement " = "CIVIC ENGAGEMENT",
                                                          "Health   " = "HEALTH ",
                                                          "Life satisfaction" = "LIFE SATISFACTION",
                                                          "Safety" = "SAFETY",
                                                          "Work Life Balance" = "WORK LIFE BALANCE",
                                               selected = "JOBS"))
               ),
               mainPanel(
                 plotOutput("radarChart"),
                 p("Every variable is measured in scale of 0 to 10.")
               )
             )


    ),
    tabPanel("Info",
             fluidRow(
               shiny::column(6, offset = 0, h1("Probando"))

             )
    )
  )
),

server <- function(input, output) {


  output$radarChart <- renderPlot({
    nba$TEAM <- NULL
    pl1 <- subset(nba, COUNTRIES == input$country1)
    pl2 <- subset(nba, COUNTRIES == input$country2)
    merge1 <- rbind(header, pl1)
    merge2 <- rbind(merge1, pl2)
    ###
    datasetInput <- reactive({
      perm.vector <- as.vector(input$checkGroup)
      perm.vector
    }) 

    ###
    final = subset(merge2, select = c(input$checkGroup) )
    final$COUNTRIES <- NULL
    colors_border=c( rgb(0.2,0.5,0.5,0.9), rgb(0.8,0.2,0.5,0.9) , rgb(0.7,0.5,0.1,0.9) )
    colors_in=c( rgb(0.2,0.5,0.5,0.4), rgb(0.8,0.2,0.5,0.4) , rgb(0.7,0.5,0.1,0.4) )
    radarchart( final  , axistype=1 , 
                #custom polygon
                pcol=colors_border , pfcol=colors_in , plwd=4 , plty=1,
                #custom the grid
                cglcol="grey", cglty=1, axislabcol="grey", cglwd=0.8,
                #custom labels
                vlcex=0.8 
    )
    legend(x=1.5, y=1, legend = c(input$COUNTRIES1, input$COUNTRIES2), bty = "n", pch=20 , col=colors_in , text.col = "grey", cex=1.2, pt.cex=3)
    datasetInput
  })

}
)

shinyApp(ui = ui, server = server)

Thanks for help in advance!

AndrzejEIT
  • 11
  • 3
  • Missing 2 csv files: https://ufile.io/fvgt8 https://ufile.io/s2y68 – AndrzejEIT May 22 '18 at 21:15
  • This is a lot of code and file downloading for people trying to help you to go through. You'll be more likely to get answers if you edit your code to make it more reproducible (use a built in dataset, or generate some data) and minimal (only show us the part of the code that is causing the error). See [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Jan Boyer May 22 '18 at 21:22
  • sometimes it is due to a misplaced parenthesis or comma. – MLavoie May 22 '18 at 21:25

1 Answers1

1

Missed a parenthesis to close sidebarPanel in your ui. Revised UI code below:

ui <- fluidPage(
  titlePanel("NBA Analysis Application"),
  navlistPanel(
    "Menu",
    tabPanel("COUNTRIES Comparison",
       sidebarLayout(
           sidebarPanel(
             selectInput("country1", "Choose the first country:",
                         choices = countriesName),
             selectInput("country2", "Choose the second contry:",
                         choices = countriesName),
             column(12, 
                 checkboxGroupInput("checkGroup", 
                    h3("Choose the stats that you want to compare (at least 3):"), 
                    choices = list("Housing" = "HOUSING", 
                                   "Income" = "INCOME", 
                                   "Jobs" = "JOBS",
                                   "Community" = "COMMUNITY",
                                   "Education" = "EDUCATION",
                                   "Environment" = "ENVIRONMENT",
                                   "Civic Engagement " = "CIVIC ENGAGEMENT",
                                   "Health   " = "HEALTH ",
                                   "Life satisfaction" = "LIFE SATISFACTION",
                                   "Safety" = "SAFETY",
                                   "Work Life Balance" = "WORK LIFE BALANCE",
                                   selected = "JOBS"))
                    )
             ),
           mainPanel(
              plotOutput("radarChart"),
              p("Every variable is measured in scale of 0 to 10.")
           )
       )
    ),
    tabPanel("Info",
       fluidRow(
         shiny::column(6, offset = 0, h1("Probando"))
       )
    )
  )
)
phalteman
  • 3,442
  • 1
  • 29
  • 46
  • Thank you for reviewing the code!! Unfortunately I have now another message from console: Error : cannot coerce type 'closure' to vector of type 'character' – AndrzejEIT May 23 '18 at 07:35
  • @AndrzejEIT - That’s a very common server-side error that many people run into when working with reactive values. I’m sure that with a little searching on this site you’ll find a solution to a very similar example. – phalteman May 23 '18 at 16:04