Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in tagAssert Creating a Shiny Dashboard

I'm making a Shiny dashboard, and I'm getting this error:

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

And I have no idea what it means. Googling gives me nothing. I have my dashboardHeader, dashboardSidebar, dashboardBody. Here is the full code, because I have no idea where the error is. The Shiny app works fine normally, it's just putting it in the dashboard that is breaks.

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")
  })
}

)
like image 726
Avenn Avatar asked Jul 31 '18 19:07

Avenn


People also ask

Is it possible to integrate Elasticsearch data into a shiny dashboard?

However, while building the dashboard, there is an immediate implementation barrier of connecting Amazon Elasticsearch Service and that motivates me to write this article. This article demonstrates the integration of Elasticsearch data into a Shiny dashboard.

How do I create an interactive dashboard?

Essential elements for an interactive dashboard are the use of widgets. There are many resources for creating Shiny widgets, for example here. Once you have an idea in mind then you can simply search for the right widget and place that into the ui.R file.

How to build a dashboard to showcase business ideas?

When attempting to build a dashboard to showcase business ideas, typically one needs to integrate data from NoSQL database, relational database and search engine. Thus dashboards like Kibana or Google Data Studio are not suitable choices as the flexibility of multiple data source is limited.

What are the essential elements for an interactive dashboard?

Essential elements for an interactive dashboard are the use of widgets. There are many resources for creating Shiny widgets, for example here. Once you have an idea in mind then you can simply search for the right widget and place that into the ui.R file. Apart from that, some Shiny dashboard elements can be found here.


1 Answers

  • Your sidebarMenu() is outside dashboardSidebar()
  • You wrote plotoutput() instead of plotOutput

YOUR CODE (UPDATED):

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")
  })
}

)
like image 99
Urvah Shabbir Avatar answered Oct 27 '22 12:10

Urvah Shabbir