简体   繁体   中英

Working through "R Projects for Dummies" and ran into error message

As the title says. I have entered the code exactly as it is the book, but I run into this error message: "Error in shiny::tabsetPanel(..., id=id, selected = selected): argument is missing, with no default"

I have no idea what is missing.

Here is the code:

library(shinydashboard)

ui<- dashboardPage(
    dashboardHeader(title= "Uniform Distribution"),
    dashboardSidebar(),
    dashboardBody(
        fluidRow(
            column(width =6,
                box(title = "Select a Number",
                    solidHeader = TRUE,
                    background = "yellow",
                    status = "warning",
                    width = NULL,
                    height = 312,
                    sliderInput(inputId = "number",
                            label = "",
                            value = 500, min = 25, max = 1000)),
                box(
                    background= "light-blue",
                    solidHeader = TRUE,
                    status ="primary",
                    title = "Histogram",
                    width = NULL,
                    plotOutput("hist", height = 250))),
            
            column(width = 6,
                   tabBox(
                       title ="Central Tendency",
                       id ="tabs1", height = 120, width =NULL,
                       tabPanel("Mean", h2(textOutput("meantext")),width=NULL),
                       tabPanel("Median", h2(textOutput("mediantext")),width=NULL),
                   ),
                   
                   tabBox(
                       title ="Variability",
                       id ="tabs2", height = 120, width =NULL,
                       tabPanel("Variance", h2(textOutput("vartext")),width=NULL),
                       tabPanel("Standard Deviation", h2(textOutput("sdtext")),width=NULL))
        )
    )
))

server <- function(input,output){
    histdata <- reactive({runif(input$number, min=0, max = 1)})
    output$hist <- renderPlot({
        hist(histdata(), xlab = "Value",
             main= paste(input$number,"random values between 0 and 1"))
    })
    
    output$meantext <- renderText({
        paste("Mean =", round(mean(histdata()),3))})
    
    output$mediantext <- renderText({
        paste("Median =", round(median(histdata()),3))})
    
    output$vartext <- renderText({
        paste("Variance =", round(var(histdata()),3))})
    
    output$sdtext <- renderText({
        paste("Standard Deviation =", round(sd(histdata()),3))})
}

shinyApp(ui, server)

You have tabPanels outside of tabsetPanels. Your tabPanels need to wrapped inside tabsetPanel() or navBarPage()

See below:

ui<- dashboardPage(
  dashboardHeader(title= "Uniform Distribution"),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      column(width =6,
             box(title = "Select a Number",
                 solidHeader = TRUE,
                 background = "yellow",
                 status = "warning",
                 width = NULL,
                 height = 312,
                 sliderInput(inputId = "number",
                             label = "",
                             value = 500, min = 25, max = 1000)),
             box(
               background= "light-blue",
               solidHeader = TRUE,
               status ="primary",
               title = "Histogram",
               width = NULL,
               plotOutput("hist", height = 250))),
      
      column(width = 6,
             tabBox(
               title ="Central Tendency",
               id ="tabs1", height = 120, width =NULL,
               tabsetPanel(
                 tabPanel("Mean", h2(textOutput("meantext")),width=NULL),
                 tabPanel("Median", h2(textOutput("mediantext")),width=NULL)
               )
               
             ),
             
             tabBox(
               title ="Variability",
               id ="tabs2", height = 120, width =NULL,
               tabsetPanel(
                 tabPanel("Variance", h2(textOutput("vartext")),width=NULL),
                 tabPanel("Standard Deviation", h2(textOutput("sdtext")),width=NULL)
               )
               )
      )
    )
  ))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM