无法读取.RData文件输入 [英] Can't read an .RData fileInput
本文介绍了无法读取.RData文件输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用fileInput导入.RData文件,但它不起作用,我收到以下错误消息:
my.data$TYPE_DE_TERMINAL中出错:$OPERATOR对于 原子矢量
dt <- reactive({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
load(inFile$datapath)
})
GetData <- reactive({
my.data <- dt()
当我使用手动导入的.RData尝试我的应用程序时,它工作正常(我直接将dt()与我的目录中的数据帧放在一起).
推荐答案
以下示例解决了此问题。它允许您上传所有.RData
文件。
感谢@Spacedman为我提供了加载数据的更好方法: 将文件加载到新环境中并从那里获取它。
由于示例是"独立的",我将存储两个向量的顶部部分插入到磁盘中,以便稍后加载和绘制它们。
library(shiny)
# Define two datasets and store them to disk
x <- rnorm(100)
save(x, file = "x.RData")
rm(x)
y <- rnorm(100, mean = 2)
save(y, file = "y.RData")
rm(y)
# Define UI
ui <- shinyUI(fluidPage(
titlePanel(".RData File Upload Test"),
mainPanel(
fileInput("file", label = ""),
actionButton(inputId="plot","Plot"),
plotOutput("hist"))
)
)
# Define server logic
server <- shinyServer(function(input, output) {
observeEvent(input$plot,{
if ( is.null(input$file)) return(NULL)
inFile <- isolate({input$file })
file <- inFile$datapath
# load the file into new environment and get it from there
e = new.env()
name <- load(file, envir = e)
data <- e[[name]]
# Plot the data
output$hist <- renderPlot({
hist(data)
})
})
})
# Run the application
shinyApp(ui = ui, server = server)
这篇关于无法读取.RData文件输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文