Home > Blockchain >  In R/Shiny why my ggplots are not displayed when I am working with modules?
In R/Shiny why my ggplots are not displayed when I am working with modules?

Time:11-23

This is my app code:

library(shiny)
library(tidyverse)

source('module.R')

ui <- fluidPage(
  
  tabpanel_UI("mod1")
)

server <- function(input, output, session) {
  
  tabpanel_Server("mod1")
  
}

shinyApp(ui, server)

This is my module file: 'module.R'

tabpanel_function <- function(x,n){     
   
  tabPanel(paste0("Panel",x),               
           plotOutput(paste0("chart_",n))
  )      
}

tabpanel_UI <- function(id) {
  ns <- NS(id)
  tagList(        
    tabsetPanel(id = ns("x"),
                tabPanel("Panela"),
                tabPanel("Panelb"),
                tabPanel("Panelc")     
                
    )      
  )
}

tabpanel_Server <- function(id) {
  moduleServer(
    id,
    function(input, output, session) {         
      
      1:4 %>% map(~ tabpanel_function(.x, n = .x) %>% appendTab("x", .))          
      
      output$chart_1 <- renderPlot({
        ggplot(mtcars, aes(cyl,mpg))   geom_line(color  ='red')
      })
      
      output$chart_2 <- renderPlot({
        ggplot(mtcars, aes(cyl,mpg))   geom_line(color  ='green')
      })
      output$chart_3 <- renderPlot({
        ggplot(mtcars, aes(cyl,mpg))   geom_line(color  ='blue')
      })
      
      output$chart_4 <- renderPlot({
        ggplot(mtcars, aes(cyl,mpg))   geom_line(color  ='yellow')
      })
      
    }
  )
}

What am I missing here?

This is a question: Dynamic ggplot within a dynamic panel

  • Related