r - tagAssert 创建一个 Shiny 的仪表板时出错

标签 r shiny shinydashboard

我正在制作一个 Shiny 的仪表板,但出现此错误:

Error in tagAssert(body, type = "div", class = "content-wrapper") : 
  Expected tag to be of type div

我不知道这意味着什么。谷歌搜索给我什么。我有我的dashboardHeader、dashboardSidebar、dashboardBody。这是完整的代码,因为我不知道错误在哪里。 Shiny 应用程序正常工作,只是将其放在仪表板中而已。
library(shinydashboard)

shinyApp(ui = dashboardPage(
  #Header
  dashboardHeader(title = "Basic dashboard"),

  #Sidebar
  dashboardSidebar(
    selectInput("dataset",
                "Pick a Project",
                choices = c("ALTTobacco - 5/10/17 through 6/11/17",
                            "BehavioralFactors - 2/13/17 through 3/15/17",
                            "CobbParks - 4/11/16 through 5/5/16", 
                            "CobbSeniors - 3/16/17 through 5/4/17", 
                            "DDW-16 - 6/21/16 through 6/29/16", 
                            "DDW-17 - 6/19/17 through 6/22/17", 
                            "DDW-18 - 7/9/18 through 7/13/18", 
                            "FortValley2017 - 7/19/17 through 9/10/17", 
                            "Fulton2016 - 8/15/16 through 10/24/16", 
                            "Fulton2018 - 2/19/18 through 3/17/18", 
                            "Habitat2016 - 10/3/16 through 10/12/16", 
                            "JohnsCreek - 4/5/17 through 5/22/17", 
                            "OhioFamily2016 - 9/12/16 through 10/1/16", 
                            "WrightDiabetes - 11/21/16 through 1/22/17"),
                selected = "ALTTobacco")
  ),
  sidebarMenu(
    menuItem("Dashboard", tabName = "dashboard"),
    menuItem("Different Projects", tabName = "project")
    ),

  #Body
  dashboardBody(tabItems(
    # First tab content
    tabItem(tabName = "dashboard",
            fluidRow(
              plotOutput("distPlot")
             )
            ),
# Second tab content
    tabItem(tabName = "project",
            fluidRow(
              plotoutput("distPlot2"),
              plotOutput("distPlot3"),
              plotOutput("distPlot4"),
              plotOutput("distPlot5")
            ))
    )
  )

),
server = function(input, output) {

  datasetInput <- reactive({
    switch(input$dataset,
           "ALTTobacco - 5/10/17 through 6/11/17" = ALTTobacco,
           "BehavioralFactors - 2/13/17 through 3/15/17" = BehavioralFactors,
           "CobbParks - 4/11/16 through 5/5/16" = CobbParks, 
           "CobbSeniors - 3/16/17 through 5/4/17" = CobbSeniors, 
           "DDW-16 - 6/21/16 through 6/29/16" = DDW16, 
           "DDW-17 - 6/19/17 through 6/22/17" = DDW17, 
           "DDW-18 - 7/9/18 through 7/13/18" = DDW18, 
           "FortValley2017 - 7/19/17 through 9/10/17" = FortValley2017, 
           "Fulton2016 - 8/15/16 through 10/24/16" = Fulton2016, 
           "Fulton2018 - 2/19/18 through 3/17/18" = Fulton2018, 
           "Habitat2016 - 10/3/16 through 10/12/16" = Habitat2016, 
           "JohnsCreek - 4/5/17 through 5/22/17" = JohnsCreek, 
           "OhioFamily2016 - 9/12/16 through 10/1/16" = OhioFamily2016, 
           "WrightDiabetes - 11/21/16 through 1/22/17" = WrightDiabetes)
  })


  output$distPlot <- renderPlot({
    dataset <- datasetInput() 

    my.bp <<-ggplot(data=surv, aes(y= Completes, x=ProjectName, fill=ProjectName ) ) # Creates boxplots
    my.bp <- my.bp + geom_boxplot() # Adds color
    my.bp <- my.bp + ggtitle("Distribution of Completed Surveys by Project") # Adds a title
    my.bp <- my.bp +  ylab("Completed Surveys per Day") + xlab("Project") # Adds kaveks
    my.bp <- my.bp + coord_flip()
    my.bp

  })
  output$distPlot2 <- renderPlot({
    dataset <- datasetInput()
    plot(dataset$Date2, dataset$Completes, 
         xlab = "Number of Days Since Beginning Survey", 
         ylab = "Number of Completed Surveys Per Day",
         title = "Completed Surveys by Number of Days Since Survey Began")
    lines(dataset$Date2, dataset$Completes)
    abline(h=mean(dataset$Completes, na.rm=TRUE), col="red")
  })
  output$distPlot3 <- renderPlot({
    dataset <- datasetInput()
    plot(dataset$Dials, dataset$Completes,
         xlab = "Number of Dials Made in a Day",
         ylab = "Number of Completed Surveys per Day",
         title = "Completed Surveys Compared to Dials Made per Day")
    lines(dataset$Dials[order(dataset$Dials)], dataset$Completes[order(dataset$Dials)])
    abline(h=mean(dataset$Completes, na.rm=TRUE), col="red")
  })
  output$distPlot4 <- renderPlot({
    dataset <- datasetInput()
    plot(dataset$Date2, dataset$Dials,
         xlab = "Number of Days Since Beginning Survey",
         ylab = "Number of Dials Made in a Day",
         tite = "Number of Dials Made per Day Since Survey Began")
    lines(dataset$Date2[order(dataset$Date2)], dataset$Dials[order(dataset$Date2)])
    abline(h=mean(dataset$Dials, na.rm=TRUE), col="red")
  })
  output$distPlot5 <- renderPlot({
    dataset <- datasetInput()
    dataset$DialRatio <- dataset$Dials / dataset$Intervierwers
    plot(dataset$Date2, dataset$DialRatio,
         xlab = "Number of Days Since Beginning Survey",
         ylab = "Ratio of Dials Made over Interviewers Present",
         title = "Ratio of Dials Made to Interviewers Present Since Survey Began")
    lines(dataset$Date2[order(dataset$Date2)], dataset$DialRatio[order(dataset$Date2)])
    abline(h=mean(dataset$DialRatio, na.rm=TRUE), col="red")
  })
}

)

最佳答案

  • 您的 sidebarMenu()在外面 dashboardSidebar()
  • 你写了 plotoutput()而不是 plotOutput

  • 您的代码(已更新):
    library(shinydashboard)
    library(shiny)
    
    shinyApp(ui = dashboardPage(
      #Header
      dashboardHeader(title = "Basic dashboard"),
    
      #Sidebar
      dashboardSidebar(
        selectInput("dataset",
                    "Pick a Project",
                    choices = c("ALTTobacco - 5/10/17 through 6/11/17",
                                "BehavioralFactors - 2/13/17 through 3/15/17",
                                "CobbParks - 4/11/16 through 5/5/16", 
                                "CobbSeniors - 3/16/17 through 5/4/17", 
                                "DDW-16 - 6/21/16 through 6/29/16", 
                                "DDW-17 - 6/19/17 through 6/22/17", 
                                "DDW-18 - 7/9/18 through 7/13/18", 
                                "FortValley2017 - 7/19/17 through 9/10/17", 
                                "Fulton2016 - 8/15/16 through 10/24/16", 
                                "Fulton2018 - 2/19/18 through 3/17/18", 
                                "Habitat2016 - 10/3/16 through 10/12/16", 
                                "JohnsCreek - 4/5/17 through 5/22/17", 
                                "OhioFamily2016 - 9/12/16 through 10/1/16", 
                                "WrightDiabetes - 11/21/16 through 1/22/17"),
                    selected = "ALTTobacco"),
        sidebarMenu(
          menuItem("Dashboard", tabName = "dashboard"),
          menuItem("Different Projects", tabName = "project")
        )
      ),
    
      #Body
      dashboardBody(tabItems(
        # First tab content
        tabItem(tabName = "dashboard",
                fluidRow(
                  plotOutput("distPlot")
                )
        ),
        # Second tab content
        tabItem(tabName = "project",
                fluidRow(
                  plotOutput("distPlot2"),
                  plotOutput("distPlot3"),
                  plotOutput("distPlot4"),
                  plotOutput("distPlot5")
                ))
      )
      )
    
    ),
    server = function(input, output) {
    
      datasetInput <- reactive({
        switch(input$dataset,
               "ALTTobacco - 5/10/17 through 6/11/17" = ALTTobacco,
               "BehavioralFactors - 2/13/17 through 3/15/17" = BehavioralFactors,
               "CobbParks - 4/11/16 through 5/5/16" = CobbParks, 
               "CobbSeniors - 3/16/17 through 5/4/17" = CobbSeniors, 
               "DDW-16 - 6/21/16 through 6/29/16" = DDW16, 
               "DDW-17 - 6/19/17 through 6/22/17" = DDW17, 
               "DDW-18 - 7/9/18 through 7/13/18" = DDW18, 
               "FortValley2017 - 7/19/17 through 9/10/17" = FortValley2017, 
               "Fulton2016 - 8/15/16 through 10/24/16" = Fulton2016, 
               "Fulton2018 - 2/19/18 through 3/17/18" = Fulton2018, 
               "Habitat2016 - 10/3/16 through 10/12/16" = Habitat2016, 
               "JohnsCreek - 4/5/17 through 5/22/17" = JohnsCreek, 
               "OhioFamily2016 - 9/12/16 through 10/1/16" = OhioFamily2016, 
               "WrightDiabetes - 11/21/16 through 1/22/17" = WrightDiabetes)
      })
    
    
      output$distPlot <- renderPlot({
        dataset <- datasetInput() 
    
        my.bp <<-ggplot(data=surv, aes(y= Completes, x=ProjectName, fill=ProjectName ) ) # Creates boxplots
        my.bp <- my.bp + geom_boxplot() # Adds color
        my.bp <- my.bp + ggtitle("Distribution of Completed Surveys by Project") # Adds a title
        my.bp <- my.bp +  ylab("Completed Surveys per Day") + xlab("Project") # Adds kaveks
        my.bp <- my.bp + coord_flip()
        my.bp
    
      })
      output$distPlot2 <- renderPlot({
        dataset <- datasetInput()
        plot(dataset$Date2, dataset$Completes, 
             xlab = "Number of Days Since Beginning Survey", 
             ylab = "Number of Completed Surveys Per Day",
             title = "Completed Surveys by Number of Days Since Survey Began")
        lines(dataset$Date2, dataset$Completes)
        abline(h=mean(dataset$Completes, na.rm=TRUE), col="red")
      })
      output$distPlot3 <- renderPlot({
        dataset <- datasetInput()
        plot(dataset$Dials, dataset$Completes,
             xlab = "Number of Dials Made in a Day",
             ylab = "Number of Completed Surveys per Day",
             title = "Completed Surveys Compared to Dials Made per Day")
        lines(dataset$Dials[order(dataset$Dials)], dataset$Completes[order(dataset$Dials)])
        abline(h=mean(dataset$Completes, na.rm=TRUE), col="red")
      })
      output$distPlot4 <- renderPlot({
        dataset <- datasetInput()
        plot(dataset$Date2, dataset$Dials,
             xlab = "Number of Days Since Beginning Survey",
             ylab = "Number of Dials Made in a Day",
             tite = "Number of Dials Made per Day Since Survey Began")
        lines(dataset$Date2[order(dataset$Date2)], dataset$Dials[order(dataset$Date2)])
        abline(h=mean(dataset$Dials, na.rm=TRUE), col="red")
      })
      output$distPlot5 <- renderPlot({
        dataset <- datasetInput()
        dataset$DialRatio <- dataset$Dials / dataset$Intervierwers
        plot(dataset$Date2, dataset$DialRatio,
             xlab = "Number of Days Since Beginning Survey",
             ylab = "Ratio of Dials Made over Interviewers Present",
             title = "Ratio of Dials Made to Interviewers Present Since Survey Began")
        lines(dataset$Date2[order(dataset$Date2)], dataset$DialRatio[order(dataset$Date2)])
        abline(h=mean(dataset$DialRatio, na.rm=TRUE), col="red")
      })
    }
    
    )
    

    关于r - tagAssert 创建一个 Shiny 的仪表板时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51620860/

    相关文章:

    R - 无需图表即可计算布林线的公式?

    r - 在 R 数据框中估算缺失值

    r - 在按下操作按钮之前加载微调器

    css - Shiny 的 selectInput 旁边的标签

    r - 在 Shiny 应用程序中自定义 rhandsontable 颜色的正确方法

    css - shinyBS 工具提示和弹出字体不可见

    r - bs4Dash 中的 bslib::value_box 显示不符合预期

    R:二次曲线打印为数十行

    r - 如何在 Shiny 或 Shiny 的仪表板应用程序中管理我的 R 代码?

    r - Rgraphviz不再可用于R吗?