R/server.R

# Set the locale to allow for specfial characters
Sys.setlocale(category="LC_ALL", locale="C")

# Start shiny server
shinyServer(function(input, output, session) {
  iniLinks <- reactive({ if(is.null(input$filePath)) iniLinks <- NA else iniLinks <- read.csv(input$filePath$datapath) })
  selectLinks <- reactive({
    if(is.null(input$filePath)) selectLinks <- NA else {
      source("functions/selectTAL.R")
      selectLinks <- selectTAL(iniLinks(), input)
      updateSelectInput(session, "country", choices=c("All", as.character(unique(selectLinks$country))), selected=input$country)
      updateSelectInput(session, "city", choices=c("All", as.character(unique(selectLinks$city))), selected=input$city)
      updateSelectInput(session, "brand", choices=c("All", as.character(unique(selectLinks$brand))), selected=input$brand)
    }
    selectLinks    
  })
  output$selectedPagesList <- renderDataTable({ selectLinks() }, options = list(lengthMenu = c(10, 30, 50), pageLength = 10))
  comments <- reactive({
    source("functions/buildDatabase.R")
    buildDatabase(selectLinks(), input)
  })
  output$allComments <- renderDataTable({ comments() }, options = list(lengthMenu = c(10, 30, 50), pageLength = 10)) 
  output$downloadComments <- downloadHandler(
    filename = "comments.csv",
    content = function(file) { write.csv(comments(), file) }
    )
  
  
})
NicolasJBM/tripapp documentation built on Nov. 18, 2017, 8:49 a.m.