Reputation: 63
I am trying to run my shinyapp.R
(includes ui
and server
) using source("model.R")
. I want to let a user upload a data file and run model.R
in my shinyapp.R
.
How should I let model.R
run using user uploaded data set. It does not read the dataset I uploaded from the shiny app.
My code:
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))
I get the following error message:
Error in eval(ei, envir) : object 'dataset' not found
Upvotes: 1
Views: 358
Reputation: 63
I was able to figure it out, I save necessary functions as R objects and call it in shiny app. That way, you can render things as needed.
Upvotes: 1