|
| 1 | +# |
| 2 | +# This is a Shiny web application. You can run the application by clicking |
| 3 | +# the 'Run App' button above. |
| 4 | +# |
| 5 | +# Find out more about building applications with Shiny here: |
| 6 | +# |
| 7 | +# http://shiny.rstudio.com/ |
| 8 | +# |
| 9 | + |
| 10 | +library("shiny") |
| 11 | +library("shinydashboard") |
| 12 | +library("shinydashboardPlus") |
| 13 | +library("dashboardthemes") |
| 14 | +library("tidyverse") |
| 15 | +library("readxl") |
| 16 | + |
| 17 | +# Define UI for application that draws a histogram |
| 18 | +ui <- dashboardPage( |
| 19 | + header= dashboardHeader(title= "Address Geocoding", |
| 20 | + tags$li(a(href = 'http://shinyapps.company.com', |
| 21 | + icon("github"), |
| 22 | + title = ""), |
| 23 | + class = "dropdown"), |
| 24 | + tags$li(a(href = 'http://www.company.com', |
| 25 | + icon("envelope"), |
| 26 | + title = "Contact", |
| 27 | + style = "padding-top:10px; padding-bottom:10px;"), |
| 28 | + class = "dropdown") |
| 29 | + ), |
| 30 | + |
| 31 | + sidebar= dashboardSidebar(disable = TRUE), |
| 32 | + |
| 33 | + body= dashboardBody( |
| 34 | + shinyDashboardThemes(theme = "blue_gradient"), |
| 35 | + fluidPage( |
| 36 | + |
| 37 | + |
| 38 | + # Application title |
| 39 | + titlePanel("Get longitude & latitude for an address list"), |
| 40 | + |
| 41 | + # Sidebar with a slider input for number of bins |
| 42 | + sidebarLayout( |
| 43 | + # sidebarPanel( |
| 44 | + box( |
| 45 | + title="Upload your address list as CSV or Excel file and recieve the corresponding geocodes.", |
| 46 | + "After uploading your file, specify the columns that contain the address.", br(), |
| 47 | + "Either ZIP or City is a mandatory column as well as country. If all your addresses are from one country, you can choose a country from the dopdown menu.", |
| 48 | + br(), br(), |
| 49 | + fileInput( |
| 50 | + inputId = "file_upload", |
| 51 | + label= "Upload file", |
| 52 | + multiple = FALSE, |
| 53 | + accept = c(".csv", ".xlsx"), |
| 54 | + width = '30%', |
| 55 | + buttonLabel = "Browse...", |
| 56 | + placeholder = "No file selected" |
| 57 | + ), |
| 58 | + # check if file has header |
| 59 | + checkboxInput("header", "Header", TRUE), |
| 60 | + |
| 61 | + # Input: Select separator ---- |
| 62 | + radioButtons("sep", "Separator", |
| 63 | + choices = c(Comma = ",", |
| 64 | + Semicolon = ";", |
| 65 | + Tab = "\t", |
| 66 | + Pipe = "|"), |
| 67 | + selected = ","), |
| 68 | + ), |
| 69 | + |
| 70 | + mainPanel( |
| 71 | + |
| 72 | + tableOutput("preview") |
| 73 | + ) |
| 74 | + ) |
| 75 | + ) |
| 76 | + ) |
| 77 | +) |
| 78 | + |
| 79 | + |
| 80 | +# Define server logic required to draw a histogram |
| 81 | +server <- function(input, output) { |
| 82 | + |
| 83 | + output$preview <- renderTable({ |
| 84 | + |
| 85 | + # input$file1 will be NULL initially. After the user selects |
| 86 | + # and uploads a file, head of that data file by default, |
| 87 | + # or all rows if selected, will be shown. |
| 88 | + |
| 89 | + req(input$file_upload) |
| 90 | + |
| 91 | + if (str_detect(input$file_upload$datapath, "\\.csv$")){ |
| 92 | + |
| 93 | + df <- read.csv(input$file_upload$datapath, |
| 94 | + header = input$header, |
| 95 | + sep = input$sep |
| 96 | + ) |
| 97 | + return(head(df,10)) |
| 98 | + } |
| 99 | + |
| 100 | + else if (str_detect(input$file_upload$datapath, "\\.xlsx$")){ |
| 101 | + |
| 102 | + df <- read_excel(input$file_upload$datapath, |
| 103 | + col_names = input$header |
| 104 | + ) |
| 105 | + return(head(df, 10)) |
| 106 | + } |
| 107 | + |
| 108 | + else { |
| 109 | + return("Error: Wrong file format") |
| 110 | + |
| 111 | + } |
| 112 | + |
| 113 | + }, caption= "Data preview") |
| 114 | +} |
| 115 | + |
| 116 | +# Run the application |
| 117 | +shinyApp(ui = ui, server = server) |
0 commit comments