"mainPanel" is missing, with no default Shiny error

I am new to R and trying to run an app on Shiny but keep getting an error. Any insight into this error or flaws in my code would be appreciated.

ui <- 	fluidPage(
    sidebarLayout(
         sidebarPanel(
             selectInput('xcol', 'X Variable', dimnames(cdc15)[[2]]),
	selectInput('ycol','Y Variable',dimnames(cdc15)[[1]]),
             mainPanel( plotOutput('plot') ) )))
server <- function(input, output) {
     selectedData <- reactive({
         Q6[, c(input$xcol, input$ycol)]
     })
     output$plot<-renderPlot({
         plot(cdc15$X,cdc15$y)
     })}
 shinyApp(ui=ui,server=server)

!

Hi @apeach86,
Welcome to R! We're glad to have you here.
Shiny can be a pain to navigate because of all the nested parentheses and brackets. I can't fully run your example because you haven't provided reproducible data to go with it, but I fiddled around and it looks like you just your parentheses in the wrong places--you need to add a parenthesis after both selectInput items in the sidebarPanel and remove one from after the mainPanel code.

Can you tell me if this works for you? :

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput('xcol', 'X Variable', dimnames(cdc15)[[2]]),
      selectInput('ycol','Y Variable',dimnames(cdc15)[[1]])),
      mainPanel(plotOutput('plot')) ))
server <- function(input, output) {
  selectedData <- reactive({
    Q6[, c(input$xcol, input$ycol)]
  })
  output$plot<-renderPlot({
    plot(cdc15$X,cdc15$y)
  })}
shinyApp(ui=ui,server=server)

If that still doesn't work, could you post some reproducible data so it will be easier to help you answer your question? More information about how to do that here: FAQ: What's a reproducible example (`reprex`) and how do I do one?

Good luck!

1 Like

Thank you for your assistance. That was able to get the app to run but I got a new error, shown below. I tried to run the reprex package but I am not sure I ran it correctly.

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput('xcol', 'X Variable', dimnames(cdc15)[[2]]),
      selectInput('ycol','Y Variable',dimnames(cdc15)[[1]])),
      mainPanel(plotOutput('plot')) ))
#> Error in fluidPage(sidebarLayout(sidebarPanel(selectInput("xcol", "X Variable", : could not find function "fluidPage"
server <- function(input, output) {
  selectedData <- reactive({
    Q6[, c(input$xcol, input$ycol)]
  })
  output$plot<-renderPlot({
    plot(cdc15$X,cdc15$y)
  })}
shinyApp(ui=ui,server=server)
#> Error in shinyApp(ui = ui, server = server): could not find function "shinyApp"

Created on 2020-09-17 by the reprex package (v0.3.0)

It looks like in order to run this app, we'll need the data, which seems to be called "cdc15". Do you have access to that data, or can you mock up some fake data to show us the structure?

Here is a screenshot of the data I am trying to run in the app.

Hello,
I'm sure you shared this image with the best intentions, but perhaps you didnt realise what it implies.
If someone wished to use example data to test code against, they would type it out from your screenshot...

This is very unlikely to happen, and so it reduces the likelihood you will receive the help you desire.
Therefore please see this guide on how to reprex data. Key to this is use of either datapasta, or dput() to share your data as code

df <- data.frame(stringsAsFactors = FALSE,
                                    cdc15_10 = c(-0.16, NA, -0.37, NA, -0.43),
                                   cdc15_30 = c(0.09, NA, -0.22, NA, -1.33),
                                   cdc15_50 = c(-0.23, NA, -0.16, NA, -1.53))
ui <- fluidPage(
         sidebarLayout(
                 sidebarPanel(
                         selectInput('xcol', 'X Variable', dimnames(df)[[2]]),
                         selectInput('ycol','Y Variable',dimnames(df)[[1]])),
                 mainPanel(plotOutput('plot')) ))
#> Error in fluidPage(sidebarLayout(sidebarPanel(selectInput("xcol", "X Variable", : could not find function "fluidPage"
 server <- function(input, output) {
         selectedData <- reactive({
                 Q6[, c(input$xcol, input$ycol)]
             })
         output$plot<-renderPlot({
                 plot(df$X,df$y)
             })}
 shinyApp(ui=ui,server=server)
#> Error in shinyApp(ui = ui, server = server): could not find function "shinyApp"

This is confusing because you have select inputs that you use to interrogate a Q6 object that we can't see and you make a selectData reactive from that and don't use it for anything. And then in the render plot you are using a df object we haven't seen and assuming it has variables called X and Y that we can't see relate to anything else.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.