ui <- fluidPage( # Application title titlePanel("Minimal Example"), # Sidebar with a slider input for x range sidebarLayout( sidebarPanel( sliderInput("plotrange", "Maximum X value:", min = 1, max = 100, value = 50) ), # Create a plot for the XY data mainPanel( plotOutput("xyPlot") ) ) ) # Define server logic required to draw a scatterplot with a simple linear model server <- function(input, output) { library(tidyverse) MinimalExample <- read.csv("../Data/MinimalExample.csv") output$xyPlot <- renderPlot({ datasubset <- MinimalExample %>% filter(X <= input$plotrange) model <- lm(Y~X, data=datasubset) plot(Y~X, data=datasubset) abline(model) }) } # Run the application shinyApp(ui = ui, server = server) app.R ui.R server.R library(shiny) ui <- fluidPage( # Application title titlePanel("Minimal Example"), # Sidebar with a slider input for x range sidebarLayout( sidebarPanel( sliderInput("plotrange", "Maximum X value:", min = 1, max = 100, value = 50) ), # Create a plot for the XY data mainPanel( plotOutput("xyPlot") ) ) ) library(shiny) server <- function(input, output) { library(tidyverse) MinimalExample <- read.csv("../Data/MinimalExample.csv") output$xyPlot <- renderPlot({ datasubset <- MinimalExample %>% filter(X <= input$plotrange) model <- lm(Y~X, data=datasubset) plot(Y~X, data=datasubset) abline(model) }) } One-file: Two-file: Both methods are technically equivalent. Do whatever works for you