你好,RShiny社区-
对于如何在模块之间传递反应值,我仍然有一点困难。下面,我有三个模块以及顶层服务器和ui函数。这三个模块(理论上)将完成以下工作: 1) uploadTree模块将允许用户输入和读取系统发育树文件;2) paramsTree模块将是用户可以选择的多个树可视化输入,并将在从uploadTree模块导入的树上进行更改;3) displayTree模块将是显示树并基于用户输入(即align =T或F)调整可视化的模块。
然而,我仍然有一段困难的时间让它工作-最终可能是因为我仍然不清楚让模块相互对话的正确方式。按照原样,这段代码不允许显示树,并给出错误“找不到函数”align“”
建议...
下面是一个在align =T中硬编码的例子:
library(shiny)
library(ggtree)
#top-level ui
ui <-
fluidPage(
h1("phylogeny"),
sidebarPanel(
mod_uploadTree_ui("uploadTree_ui_1")),
#mod_paramsTree_ui("paramsTree_ui_1")), #commented out as this is not working
mainPanel(mod_displayTree_ui("displayTree_ui_1"))
)
#top-level server
server <- function(input, output,session) {
treeDisplay <- callModule(mod_uploadTree_server, "uploadTree_ui_1")
#params <- callModule(mod_paramsTree_server, "paramsTree_ui_1") #commented out as this is not working.
callModule(mod_displayTree_server, "displayTree_ui_1", treeDisplay)
}
#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. But I am unable to add this without an error occurring.
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 = T) #hardcoded align = T instead of based on user input
})
output$treeDisplay <- renderPlot({
make_tree()
})
}
shinyApp(ui, server)根据bretauv的建议,这里是读取系统发展史并绘制系统发展图的代码,提示对齐。
library(ggplot2)
library(treeio)
library(ggtree)
tree <- treeio::read.newick("1509MLJF6-1.dnd")
make_tree <- ggplot2::ggplot(tree) + ggtree::geom_tree() + ggtree::geom_tiplab(align = T)
make_tree

如果需要,系统发生树位于here
发布于 2020-02-02 18:59:20
每个服务器函数都必须返回一个reactive (或reactiveValues或reactiveVal),例如:
mod_uploadTree_server <- function(input, output, session){
ns <- session$ns
treeFile <- reactive({
req(input$treefile)
treeio::read.newick(input$treefile$datapath)
})
return(treeFile)
}https://stackoverflow.com/questions/60011116
复制相似问题