Hello RShiny community -
I am still having a bit of a hard time wrapping my mind around how to pass reactive values between modules. Below, I have three modules along with the top level server and ui functions. The three modules would do this (in theory) 1) uploadTree module would allow the user to input and read phylogenetic tree file; 2) paramsTree module would be multiple tree visualization inputs that the user could select and would change on the imported tree from the uploadTree module; 3) displayTree module would be the module which displays the tree and adjusts visualization based on the user input (i.e. align = T or F).
However, I am still having a difficult time in getting this to work - ultimately probably because I am still unclear of the correct way to make modules talk to each other. As it stands, this code does not allow the tree to display and gives the error 'could not find function 'align''
Suggestions....
Below is the code -
#top-level ui
app_ui <- function() {
tagList(
fluidPage(
h1("phylogeny"),
sidebarPanel(
mod_uploadTree_ui("uploadTree_ui_1"),
mod_paramsTree_ui("paramsTree_ui_1")),
mainPanel(mod_displayTree_ui("displayTree_ui_1"))
)
)
}
#top-level server
app_server <- function(input, output,session) {
treeDisplay <- callModule(mod_uploadTree_server, "uploadTree_ui_1")
params <- callModule(mod_paramsTree_server, "paramsTree_ui_1")
callModule(mod_displayTree_server, "displayTree_ui_1", treeDisplay, params$align)
}
#uploadTree module - This module will use the read.newick function to read in a phylogenetic tree
mod_uploadTree_ui <- function(id){
ns <- NS(id)
tagList(
fileInput(ns("treefile"), label="Upload a newick file, please"))
}
mod_uploadTree_server <- function(input, output, session){
ns <- session$ns
treeFile <- reactive({
req(input$treefile)
treeio::read.newick(input$treefile$datapath)
})
#paramsTree module - This module *should* include multiple tree display parameters that can be selected by the user. Here, only one parameter is included for a smaller example.
mod_paramsTree_ui <- function(id){
ns <- NS(id)
tagList(
checkboxInput(ns("alignTips"), "Align tip labels", TRUE)
)
}
mod_paramsTree_server <- function(input, output, session){
ns <- session$ns
observe({
align = reactive(input$alignTips)
})
}
#displayTree module - This module will plot the tree and will change the tree viz based on user inputs from param module
mod_displayTree_ui <- function(id, label = "Display Tree"){
ns <- NS(id)
tagList(
label,
plotOutput(ns("treeDisplay"))
)
}
mod_displayTree_server <- function(input, output, session, treeFile, align){
ns <- session$ns
make_tree <- reactive({
ggplot2::ggplot(treeFile()) + ggtree::geom_tree() + ggtree::geom_tiplab(align = align())
})
output$treeDisplay <- renderPlot({
make_tree()
})
runapp()