I have an R shiny app using golem to generate a report on NGS data. I currently have a working app that reads in data (some excel files and a pdf) and shows the graphs and tables relating to that input. I would like to have the app start with a drop down selection where I can choose which projects data will be analyzed. It will then read in the proper files which are stored in a directory matching the chosen project.
What I am having trouble with is making everything work in a reactive and dynamic way to update all of my analysis/results when I switch projects and therefore the inputs for these results. My understanding is that I need to pass reactive values (ex. dataframe) from one module where it is created to another where it is used but I cannot get any updates I make to reflect throughout the app.
I can show some code to show where what I am exploring now and explain the simplest minimal example of what I am trying to accomplish.
In this example I am only trying to pass on the selected project (coming from the Initialization module) and display it in the test module. Here I have the app server and app ui sections, as well as the two modules I am using. Initialization to pick the project and test to display it. This code works for running the app but the output never updates in the test module no matter what I do in the Initialization module.
app_server <- function(input, output, session) {
rv = reactiveValues(projectid = NULL)
initial = mod_Initialization_server("Initialization_1")
mod_test_server("test_1", project = reactive({rv$projectid}))
observeEvent(initial$trigger, {
rv$projectid = initial$projectid
})
app_ui <- function(request) {
tagList(
# Leave this function for adding external resources
golem_add_external_resources(),
shinydashboardPlus::dashboardPage(
skin = "purple",
header = shinydashboardPlus::dashboardHeader(
title = "NGS Report Generator"
),
sidebar = shinydashboard::dashboardSidebar( width = 200,
shinydashboard::sidebarMenu(
id = "tabs",
shinydashboard::menuItem("Home", tabName = "home"),
shinydashboard::menuItem("Basic Stats", tabName = "basic"))),
body = shinydashboard::dashboardBody(
shinydashboard::tabItems(
shinydashboard::tabItem("home", mod_Initialization_ui("Initialization_1")),
shinydashboard::tabItem("projinfo", mod_test_ui("test_1"))
)
)
)
)
}
mod_Initialization_ui <- function(id){
ns <- NS(id)
#This list needs to be generated by available projects
ProjectList = c("---","X", "Y")
tagList(
fluidPage(
fluidRow(
column(width = 12,
h2("Please select the project your report will be generated on")),
br(),br(),br()
),
fluidRow(
selectInput(ns("project"), label = "", choices = ProjectList)
)
)
)
}
mod_Initialization_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
initializationrv = reactiveValues(
projectid = "",
trigger = 0
)
observeEvent(input$project,{
initializationrv$project = input$project
initializationrv$trigger = initializationrv$trigger +1
})
#project = reactive({input$project})
return(initializationrv)
})
}
mod_test_ui <- function(id){
ns <- NS(id)
tagList(shinyjs::useShinyjs(),
fluidPage(h1(textOutput(ns("projectid"))))
)
}
mod_test_server <- function(id, project = ""){
moduleServer( id, function(input, output, session){
ns <- session$ns
observe(output$projectid <- renderText({
project()
}))
})
}