It turns out to be I shouldn't use ns in callmodule function names
like instead of
innerResult <- callModule(inner, ns("inner1"))
I should use
innerResult <- callModule(inner, "inner1")
But the UI function needs to be wrapped around in ns.
I rewrote the code and it worked. Here is where I found it. at the very bottom
https://shiny.rstudio.com/articles/modules.html
And this is the new code written
# load_libraries ----------------------------------------------------------
library(shiny)
library(RSQLite)
library(shinydashboard)
library(plotly)
library(data.table)
library(lubridate)
library(dbplyr)
library(shinyjs)
library(tidyverse)
library(DBI)
library(crosstalk)
library(RSQLite)
library(DT)
# source_code -------------------------------------------------------------
source('www/Modules/select_data.R')
source('www/Modules/dashboard_module.R')
source('www/Modules/emp_data.R')
source('www/Modules/CRUD_db.R')
source('www/Modules/mod_SQL_functions.R')
# front_end ---------------------------------------------------------------
main_ui <- function(id){
# namespace ---------------------------------------------------------------
ns<-NS(id)
# Ui_function -------------------------------------------------------------
dashboardPage(dashboardHeader(),
dashboardSidebar(sidebarMenu(
menuItem('MainData', icon = icon('database'),
tabName = 'sql_data_tab'),
menuItem(
'Dashboard',
icon = icon('dashboard'),
tabName = 'dashboard_tab'
),
menuItem(
'Employee',
icon = icon('user'),
tabName = 'employee_tab'
),
menuItem(
'Password',
icon = icon('users'),
tabName = 'user_tab'
)
)),
dashboardBody(tabItems(
tabItem(
tabName = 'dashboard_tab',
mod_dashboard_ui(ns('dashboardpage'))
),
tabItem(tabName = 'sql_data_tab',
mod_select_data_ui(ns('sql'))
),
tabItem(tabName = 'employee_tab',
mod_emp_ui(ns('employee'))
),
tabItem(tabName = 'user_tab',
mod_crud_ui(ns('user'))
)
)))
}
# server ------------------------------------------------------------------
main_server <- function(input, output, session) {
# namespace ---------------------------------------------------------------
ns<-session$ns
# connect_to_DB -----------------------------------------------------------
sqlite <- reactive({
dbConnect(SQLite(),
'www/main_data.sqlite')
})
# retreive_data -----------------------------------------------------------
fulldata<-callModule(mod_select_data_serve,'sql',sqlite)
# show_dashboard ----------------------------------------------------------
callModule(mod_dashboard_serve,'dashboardpage',sqlite,fulldata)
# show_employee -----------------------------------------------------------
callModule(mod_emp_serve,'employee',sqlite,fulldata)
# show_passwords ----------------------------------------------------------
callModule(mod_crud_serve,'user',sqlite())
# dbdisconnect ------------------------------------------------------------
onSessionEnded(function(){
dbDisconnect(sqlite())
})
}
# runapp ------------------------------------------------------------------
shinyApp(main_ui, main_server)
It might help you so do check it.