r - 将 R 脚本连接到闪亮以输出图像
问题描述
我正在构建一个闪亮的应用程序 GUI,以允许将四个数据文件“轻松”输入到我的 R 脚本中。我希望能够上传四个文件,从两组单选按钮中选择选项,然后单击“提交”以运行所选分析。最终输出(在我的分析代码中生成)应该是一个 .PNG 文件,该文件将 (a) 自动下载到工作目录并 (b) 显示在 GUI 的 MainPanel 上。为了了解我想要做什么,我已经包含了应用程序 UI 的代码。
library(shiny)
ui <- fluidPage(
titlePanel("Pando Nutrition Microbiome Analysis"),
sidebarLayout(
sidebarPanel(
fileInput(inputId="n1","Shared Table Upload", multiple = FALSE),
fileInput(inputId="n2", "Taxonomy File Upload", multiple=FALSE),
fileInput(inputId="n3", "Meta Table Upload", multiple=FALSE),
fileInput(inputId='ZHtree', "Phylogenetic Tree"),
radioButtons(inputId="Selection1", "Select One",
c("Fungi" = "ITS",
"Bacteria" = "16S")),
radioButtons(inputId="Selection2", "Select Analysis",
c("Shannon Diversity (Timecourse)" = "shannon1",
"Shannon Diversity (CTL vs EXP)"="shannon2",
"Top 20 Genera"="Top20Genera",
"Top 10 Genera"="Top10Genera",
"Top 5 Genera"="Top5Genera",
"Top 2 Genera"="Top2Genera"
)),
actionButton(inputId="Submit", "Submit"),
hr()
),
mainPanel(
imageOutput("figure_1.png")
)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
这是在 R Studio 中生成 16 秒“shannon1”图的 R 代码:
n1<-readline(prompt="Enter .Shared File Name:")
n2<-readline(prompt="Enter .Taxonomy File Name:")
n3<-readline(prompt="Enter Meta Table File Name:")
source("https://bioconductor.org/biocLite.R")
biocLite("phyloseq")
biocLite("DESeq2")
library(ape)
library(DESeq2)
library(dplyr)
library(ggplot2)
library(gplots)
library(lme4)
library(phangorn)
library(phyloseq)
library(plotly)
library(tidyr)
library(vegan)
library(VennDiagram)
library(shiny)
OTU = read.table(n1, header=TRUE, sep="\t")
tax = read.table(n2, header=TRUE, sep="\t")
meta=read.table(n3, header=TRUE, row.names=1, sep="\t")
row.names(OTU) = OTU$Group
OTU.clean = OTU[,-which(names(OTU) %in% c("label", "numOtus", "Group"))]
row.names(tax) = tax$OTU
tax.clean = tax[row.names(tax) %in% colnames(OTU.clean),]
tax.clean = separate(tax.clean, Taxonomy, into = c("Domain", "Phylum",
"Class", "Order", "Family", "Genus", "Species", "Strain"), sep=";")
tax.clean = tax.clean[,-which(names(tax.clean) %in% c("Size", "Strain", "OTU"))]
OTU.clean = OTU.clean[order(row.names(OTU.clean)),]
meta = meta[order(row.names(meta)),]
meta.controls <- meta[which(meta$group=='Control'),]
meta.controls = meta.controls[order(row.names(meta)),]
meta.experimental <- meta[which(meta$group=='Experimental'),]
meta.experimental = meta.experimental[order(row.names(meta)),]
meta.day0 <- meta[which(meta$collected_date=="0"),]
meta.day28 <- meta[which(meta$collected_date=="28"),]
OTU.clean.day0 <- OTU.clean[which(meta$collection_date=="0"),]
OTU.clean.day28 <- OTU.clean[which(meta$collection_date=="28"),]
meta.day0 <- meta[which(meta$collection_date=="0"),]
meta.day28 <- meta[which(meta$collection_date=="28"),]
OTU.clean.relabund <- sweep(OTU.clean,1,rowSums(OTU.clean),"/")
rowSums(OTU.clean)
rowSums(OTU.clean.relabund)
set.seed(8765)
OTU.physeq = otu_table(as.matrix(OTU.clean), taxa_are_rows=FALSE)
tax.physeq = tax_table(as.matrix(tax.clean))
meta.physeq = sample_data(meta)
meta.physeq.control = sample_data(meta.controls)
meta.physeq.experimental= sample_data(meta.experimental)
physeq.alpha = phyloseq(OTU.physeq, tax.physeq, meta.physeq)
physeq.alpha.controls =phyloseq(OTU.physeq, tax.physeq,
meta.physeq.control)
physeq.alpha.experimental=phyloseq(OTU.physeq, tax.physeq,
meta.physeq.experimental)
sample_data(physeq.alpha)$shannon.physeq <-
estimate_richness(physeq.alpha, measures="Shannon")
sample_data(physeq.alpha.controls)$shannon.physeq <-
estimate_richness(physeq.alpha.controls, measures="Shannon")
sample_data(physeq.alpha.experimental)$shannon.physeq <-
estimate_richness(physeq.alpha.experimental, measures="Shannon")
title = "Shannon Diversity Over Study Timecourse"
plot_richness(physeq.alpha, measures="Shannon", title = title) #FIGURE 1
dev.copy(png,'figure_1.png')
dev.off()
我可以让 UI 呈现得很漂亮,但是我很难将我的代码(例如,生成“shannon1”图形的 16s.R 脚本)链接到按钮。我知道服务器功能必须对“提交”功能作出反应,但它还需要依赖于(a)四个文件的输入,(b)选定的 16S 或 ITS 单选按钮,(c)选定的分析。
解决方案
推荐阅读
- html - 没有服务器语言的所有页面上的相同菜单?
- powershell - Powershell Copy-Item 目标不明确
- python - 如何检查一个变量与另一个变量共有多少个字符
- java - 覆盖属性文件中数据库连接的超时
- return - 在 SBCL 中带退货的订单事项
- powershell - 在我的 Windows 10 pro 中无法使用 Windows 虚拟机管理程序平台选项
- sql - 如何将选择查询返回的多个值连接到一个字符串
- intellij-idea - intellij:“搜索结果未加载检查互联网连接”
- merge - Autohotkey:在一个脚本中合并/组合两个脚本(#if WinActive,2 个动作)
- php - 带有 SQL 的下拉 PHP 在下拉列表中的一行中具有两个不同的查询 >(名称,编号)