本文介绍了在Shiny R App中使用read.xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我正在尝试加载excel文件并显示摘要。该文件正在加载而没有任何错误,但不显示任何内容。 这是我的代码 ui.R 库(闪亮) ShinyUI(pageWithSidebar( headerPanel(Analysis), sidebarPanel(wellPanel(fileInput('file1','Choose XLSX File', accept = c('sheetName','header'),multiple = FALSE))), mainPanel( tabsetPanel( tabPanel(Tab1,h4(Summary),htmlOutput(summary))))) server.R 库(闪亮) ShinyServer(function(input,output){ dataset = reactive({ infile = input $ file1 if( is.null(infile)) return(NULL) infile_read = read.xlsx(infile $ datapath,1) return(infile_read) }) 输出$ summary< - renderPrint({ summary = summary(dataset()) return(summary)}) outputOptions(输出,summary,suspendWhenHidden = FALSE) }) 解决方案我还没有测试过,但是看起来你实际上并没有从 dataset()返回任何东西。将功能更改为: dataset = reactive({ infile = input $ file1 if(is.null(infile)) return(NULL) read.xlsx(infile $ datapath,1) }) 当您执行 infile_read = read.xlsx(infile $ datapath,1) ,您正在将文件读入 infile_read ,但您实际上并没有返回。反应器工作只是看起来任何R功能真的。尝试运行这个: f< - function()x< - 10 f() 您应该会看到 f()不返回任何内容。所做的一切只是做一个无处不在的作业。要实际返回'hello',您可以: f x< - 'hello'x } 或者只是: f< - function()'hello' I am trying to load an excel file and display the summary. The file is loading without any errors but not displaying anything.Here is my codeui.Rlibrary(shiny)shinyUI(pageWithSidebar( headerPanel("Analysis"), sidebarPanel(wellPanel(fileInput('file1', 'Choose XLSX File', accept=c('sheetName', 'header'), multiple=FALSE))),mainPanel(tabsetPanel( tabPanel("Tab1",h4("Summary"), htmlOutput("summary")))))server.R library(shiny)shinyServer(function(input, output) { dataset = reactive({ infile = input$file1 if (is.null(infile)) return(NULL) infile_read = read.xlsx(infile$datapath, 1) return(infile_read) }) output$summary <- renderPrint({ summary = summary(dataset()) return(summary) }) outputOptions(output, "summary", suspendWhenHidden = FALSE)}) 解决方案 I haven't tested this, but it looks like you're not actually returning anything from dataset(). Change the function to:dataset = reactive({ infile = input$file1 if (is.null(infile)) return(NULL) read.xlsx(infile$datapath, 1)})When you do infile_read = read.xlsx(infile$datapath, 1), you're reading the file into infile_read but then you're not actually returning it. Reactives work just look any R function really. Try running this:f <- function() x <- 10f()You should see that f() doesn't return anything. All it's doing is making an assignment that goes nowhere. To actually return 'hello' you would do:f <- function() { x <- 'hello' x}Or just:f <- function() 'hello' 这篇关于在Shiny R App中使用read.xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-08 18:17