首页 > 解决方案 > 上传数据文件并在 Shiny 应用程序中运行 source.R

问题描述

我正在shinyapp.R尝试使用. 我想让用户上传数据文件并 在我的.uiserversource("model.R")model.Rshinyapp.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

标签: rshiny

解决方案


我能够弄清楚,我将必要的函数保存为 R 对象并在闪亮的应用程序中调用它。这样,您可以根据需要渲染事物。


推荐阅读