【发布时间】:2018-11-02 22:38:28
【问题描述】:
我有一个闪亮的应用程序,我想做的是在一个选项卡中打印标题或完整数据框,在另一个选项卡中打印摘要,最后在第三个选项卡中打印图表。出于某种原因,我能够在前两个选项卡中生成表格和摘要,但不能在绘图中生成。我不知道我做错了什么。
这是我的ui.R 脚本
library(shiny)
library(shinyFiles)
shinyUI(pageWithSidebar(
headerPanel(
'Selections with shinyFiles',
'shinyFiles example'
),
sidebarPanel(
tags$h3('Select your file'),
# Shiny button
shinyFilesButton(id = 'file', label = 'File select', title = 'Please select a file', multiple = FALSE),
tags$h3('Select your options for table'),
# Horizontal line ----
br(),
# Input: Checkbox if file has header ----
checkboxInput("header", "Header", TRUE),
# Input: Select separator ----
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
# Input: Select quotes ----
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"'),
# Horizontal line ----
tags$hr(),
# Input: Select number of rows to display ----
radioButtons("disp", "Display",
choices = c(Head = "head",
All = "all"),
selected = "head"),
tags$h3('Select your options for plotting'),
br(),
# Input:
radioButtons("sho", "Show",
choices = c(Yes = "yes",
No = "no"),
selected = "yes")
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Table", dataTableOutput("contents")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Plot", plotOutput("plt"))
)
))
)
这是我的server.R 脚本
library(shiny)
library(shinyFiles)
shinyServer(function(input, output, session) {
shinyFileChoose(input, 'file', roots=c(wd='/Users/upendra_35/Documents/CyVerse/Images_apps/DE/VICE/'), filetypes=c('', 'csv'))
shinySaveButton("save", "Save file", "Save file as ...", filetype=c('', "csv"))
output$contents <- renderDataTable({
inFile <- parseFilePaths(roots=c(wd='/Users/upendra_35/Documents/CyVerse/Images_apps/DE/VICE/'), input$file)
if( NROW(inFile)) {
df <- read.csv(as.character(inFile$datapath),
header = input$header,
sep = input$sep,
quote = input$quote)
if(input$disp == "head") {
return(head(df))
}
else {
return(df)
}
}
})
output$summary <- renderPrint({
inFile <- parseFilePaths(roots=c(wd='/Users/upendra_35/Documents/CyVerse/Images_apps/DE/VICE/'), input$file)
if( NROW(inFile)) {
df <- read.csv(as.character(inFile$datapath),
header = input$header,
sep = input$sep,
quote = input$quote)
summary(df)
}
})
output$plt <- renderPlot({
inFile <- parseFilePaths(roots=c(wd='/Users/upendra_35/Documents/CyVerse/Images_apps/DE/VICE/'), input$file)
if( NROW(inFile)) {
df <- read.csv(as.character(inFile$datapath),
header = input$header,
sep = input$sep,
quote = input$quote)
if(input$sho == "yes") {
manh <- manhattanr(df, chr = "chrom", bp = "pos", p = "P", snp = "marker")
manhattanly(manh, col=c("#D2691E","#800080","#6495ED","#9ACD32"), point_size=7, showlegend = FALSE,
xlab = "Chromosome", ylab = "-log10(p)", suggestiveline_color = "blue", suggestiveline_width = 2,
genomewideline =FALSE, title = "")
}
else {
print("No plot")
}
}
})
})
当我在 R 控制台中手动运行时,该图的代码肯定有效。
【问题讨论】:
-
你试过在 R 中渲染吗?