r - 上传数据文件并在 Shiny 应用程序中运行 source.R
问题描述
我正在shinyapp.R
尝试使用. 我想让用户上传数据文件并 在我的.ui
server
source("model.R")
model.R
shinyapp.R
我应该如何让model.R
使用用户上传的数据集运行。它不会读取我从闪亮应用上传的数据集。
我的代码:
source("model.R")
server <- function(input, output){
dataset <- reactive({
infile <- input$datafile
if( is.null(infile) ) {
return(NULL)
} else {
as.data.frame(read.csv(infile$datapath, header=TRUE))
}
})
output$plot <- renderPlot({pred_plot})
})
ui <- fluidPage(fileInput("datafile", "Choose data file", accept = c('text/csv','.csv','.xlsx') ),
mainPanel(plotOutput("plot")
)
runApp(list(ui = ui, server = server))
我收到以下错误消息:
Error in eval(ei, envir) : object 'dataset' not found
解决方案
我能够弄清楚,我将必要的函数保存为 R 对象并在闪亮的应用程序中调用它。这样,您可以根据需要渲染事物。
推荐阅读
- javascript - 如何在 ReactJs 中管理样式
- javascript - Javascript 无法在数字“100”上创建属性“guid”
- c# - Asp.net Core 不绑定模型
- three.js - THREEJS:用不同颜色清除RT和默认FBO
- sql - 如何在postgresql中按用户分组选择
- node.js - npm 完全死机,ERR_TLS_CERT_ALTNAME_INVALID,主机名/IP 与证书的替代名称不匹配:主机:registry.npmjs.org
- javascript - 与 JS 相同的 html 文件的动态链接
- android - 等待 onComplete 回调
- macos - 为什么在 MacOS 上用户发出的 ps 命令是由 root 用户执行的?
- javascript - Fabric Canvas - 图像分辨率很差