is there something i'm missing in displaying plotOutput() (bs4Dash)

63 Views Asked by At
 library(shiny)
library(gapminder)
library(bbplot)
library(tidyverse)
library(bs4Dash)

year_range <- range(gapminder[["year"]])

ui <- dashboardPage(
    header = dashboardHeader(
      title = dashboardBrand(
        title = "LE",
        color = "gray"
      )
      
    ),
    sidebar = dashboardSidebar(
      width = ,
      skin = "light",
      
      sidebarMenu(
        id = "sidemenu",
        
        menuItem(
          "plotme",
          tabName = "plotme",
          icon = icon("sliders")
        )
        
      )
      
    ),
    
    body = dashboardBody(
      tabItem(
        tabItem(
          tabName = "plotme",
          fluidRow(
            column(
              width = 12,
              plotOutput("plotme")
            )
          )
        )
      )
    ),
    
    controlbar = dashboardControlbar(
      collapsed = FALSE,
      pinned = TRUE,
      skin = "light",
      
      controlbarMenu(
        id = "plotme",
        
        controlbarItem(
        
            title = "Filter:",
            selectInput("continent", "Continent",
                        choices = unique(gapminder$continent)),

          
            selectInput("country", "Country",
                        choices = NULL),
            
            sliderInput("year",
                        "Select The Year Range:",
                        min = year_range[[1]],
                        max = year_range[[2]],
                        value = c(year_range[[1]], year_range[[2]]),
                        sep = "",
                        step = 1)
            
          
        )
        
      )
    ),
)



server <- function(input, output, session) {
  
  continent_data <- reactive({
    gapminder %>%
      filter(continent == input$continent
             & year >= input$year[[1]] | year <= input$year[[2]])
  })
  
  
  observeEvent(continent_data(), {
    freezeReactiveValue(input, "country")
    choices <- unique(continent_data()$country)
    updateSelectInput(session, "country", choices = choices)
  })
  
  country_data <- reactive({
    req(input$continent)
    continent_data() %>%
      filter(country == input$country
             & year >= input$year[[1]] & year <= input$year[[2]])
  })
  
  
  output$plot <- renderPlot({
    req(input$country)
    ggplot(country_data(), aes(year, lifeExp)) +
      geom_line(colour = "#1380A1", size = 1) +
      geom_hline(yintercept = 0, size = 1, colour="#333333")
  }, res = 96)
  

  
}


shinyApp(ui = ui, server = server)

I have checked the reactive elements and it seems fine. My guess is the issue might be from the menuItems() or from dashboardcontrolbar()

The UI is displaying alright but the plotOutput is not showing

I have checked the reactive elements and it seems fine. My guess is the issue might be from the menuItems() or from dashboardcontrolbar()

The UI is displaying alright but the plotOutput is not showing

1

There are 1 best solutions below

0
On

I didn't try the app but maybe the problem is with the id's.

You are using plotOutput("plotme") in the UI and output$plot in the server function.