Hi,
I'm trying to make my first Shiny app using modules.
I faced a problem with the plot generated by the module but returns only "blank space". The same code pasted directly to the ui/server works just fine. Could anyone help me find where my syntax wrong?
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(ggplot2)
#UI module that should create a fluidRow with my plot
mod_home_tab_ui <- function(id){
ns <- NS(id)
home_tab = fluidRow(
shinydashboardPlus::box(
title = "Motivation",
icon = shiny::icon("question"),
collapsible = TRUE,
plotOutput(outputId = "pubs_pl")
)
)
return(home_tab)
}
#Server module to render plot
mod_home_tab_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
output$pubs_pl <- renderPlot({
ggplot2::ggplot(data = data.frame(x = rnorm(10),
y = rnorm(10)),
ggplot2::aes(x = x, y = y))+
ggplot2::geom_point()})
})
}
ui <- shinydashboardPlus::dashboardPage(
# Application title
header = shinydashboardPlus::dashboardHeader(),
# Sidebar with a slider input for number of bins
sidebar = shinydashboardPlus::dashboardSidebar(),
body = shinydashboard::dashboardBody(
#This does not work
mod_home_tab_ui("home_tab_ui_1"),
#This works fine
fluidRow(
shinydashboardPlus::box(
title = "Motivation",
icon = shiny::icon("question"),
collapsible = TRUE,
plotOutput(outputId = "pubs_pl2")
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
# This does not work
mod_home_tab_server("home_tab_ui_1")
#This works fine
output$pubs_pl2 <- renderPlot({
ggplot2::ggplot(data = data.frame(x = rnorm(10),
y = rnorm(10)),
ggplot2::aes(x = x, y = y))+
ggplot2::geom_point()})
}
# Run the application
shinyApp(ui = ui, server = server)