1

I am trying to a build a reactive shiny app where I am letting the end user upload a csv file and train my model on the uploaded file. The uploaded file could contain multiple target variables and I was hoping I could give selectinput option to the users such that the model runs for the selected target variables. So far I have been able to provide option to upload file and read the data to run the model. However I have not been able to figure how can I assign the target variable based on the user input. This is how far I am in terms of code

UI-LOGIC

sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
    menuItem("Visit-us", icon = icon("send",lib='glyphicon'), 
             href = "abc.com"),
    fileInput("datafile", "Choose CSV File",
              accept = c(
                "text/csv",
                "text/comma-separated-values,text/plain",
                ".csv")),
    tags$hr(),
    checkboxInput('header', 'Header', TRUE),
    radioButtons('sep', 'Separator',
                 c(Comma=',',
                   Semicolon=';',
                   Tab='\t'),
                 ','),
    selectInput(
      "select",
      label = h3("Select Channel"),
      choices = c("Users", "New_Users"),
      selectize = TRUE,
      selected = "All")
 )
)

SERVER LOGIC

server <- function(input, output, session) {
  getData <- reactive({
    inFile <- input$datafile
    if (is.null(input$datafile))
      return(NULL)
    data2<-read.csv(inFile$datapath, header=input$header, sep=input$sep, 
                    quote=input$quote)
    #save(data2, file = "dataread.RData")
    return(data2)
  })

  adstock <- function(x, rate=0){
    return(as.numeric(stats::filter(x=x, filter=rate, method="recursive")))
  }

  model <- reactive({
    raw_data <- getData()
  observeEvent(input$select,{
  target <- input$select
})
    ts <- ts(raw_data$target, frequency = 12, start=c(2016,07))
    decomposition <- decompose(ts)


    mod <- nls(target~b0+b1*adstock(variable, rate),data = raw_data,
               start=c(b0=1, b1=1, rate=0))
})
}

The target users in the model should come from the input in the UI.

Please help how to resolve this.

Thanks a lot in advance !!

phalteman
  • 3,442
  • 1
  • 29
  • 46
Analytics_TM
  • 493
  • 6
  • 28

0 Answers0