I am trying to run an R Script as a R Shiny App. From the ui, the user will upload a .csv file and input 4 numeric variables. These variables should be passed through the function and it will generate a final_table which should be displayed as output in the Shiny App. Currently, the variables are being passed through the function but not resulting in the final table. I am new with RShiny, appreciate your help in making this work.
my_function.R is the script file which contains the function my_function(). This in fact is a 500 line R script compressed into a function for ease of use.
my_function <- function(tbl_load, ts_freq, ts_start_yr, ts_start_month, seasonal_cat) {
..........
return(collect_ALL_final_fair)
}
ui.R
library(shiny)
fluidPage(
titlePanel("Elasticity Tool"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose datatable csv file', accept=c('.csv')),
numericInput("ts_freq", "Time series frequency:", 52, min = 1, max = 100),
numericInput("ts_start_yr", "Starting year:", 2013, min = 1990, max = 2030),
numericInput("ts_start_month", "Starting month:", 3, min = 1, max = 12),
numericInput("seasonal_cat", "Seasonal Category", 0, min = 0, max = 1),
br(),
actionButton("goButton", label = "Run tool"),
br()
),
mainPanel(
tabsetPanel(type = 'tabs',
tabPanel("Output", tableOutput('contents2'))
)
)
)
)
server.R
library(shiny)
library(datasets)
source("my_function.R")
#packages
library("glmnet")
library(Matrix)
library(dplyr)
library(forecast)
library(zoo)
library(stats)
library(car)
options(scipen = 999)
shinyServer(function(input, output) {
observeEvent(input$goButton, {
tbl_load <- input$file1
ts_freq <- input$ts_freq
ts_start_yr <- input$ts_start_yr
ts_start_month <- input$ts_start_month
seasonal_cat <- input$seasonal_cat
output$contents2 <- renderDataTable({
my_function(tbl_load, ts_freq, ts_start_yr, ts_start_month, seasonal_cat)
})
})
})