test/app.R

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)
library(tidyverse)
library(leaflet)
library(rgdal)

country <- readOGR(dsn = tmp, layer = "ne_110m_admin_0_countries", encoding   = "UTF-8")
business<-country[country@data$admin %in% c("Brazil","Colombia","Panama","Kazakhstan","Argentina","India","","Chile","Dominican Republic","United Kingdom","El Salvador","United States of America"),]
business@data$category <- factor(sample.int(20L, nrow(business@data), FALSE))


# Define UI for application that draws a histogram
ui <- navbarPage("Market Portal",
                 tabPanel("About",
                          bootstrapPage(
                              leafletOutput("Map",width="100%",height="800px"),
                              absolutePanel(top=100, right=50,
                                            selectInput("Business", "Business", c("Brazil","Colombia","Panama","Kazakhstan","Argentina","India","Chile","Dominican Republic","United Kingdom","El Salvador","United States of America"), selected="")
                              ))))

# Define server logic required to draw a histogram
server <- function(input, output) {

    output$Map <- renderLeaflet({
        factpal <- colorFactor(topo.colors(20), business@data$category)
        state_popup <- paste0("<strong>Name of the country </strong>",
                              business$admin,
                              "<br><strong> information is  </strong>",
                              business$economy)
        leaflet() %>%
            addProviderTiles("CartoDB.Positron") %>%
            addPolygons(data=business,
                        layerId=~admin,
                        fillColor= ~factpal(category),
                        fillOpacity = 0.7,
                        color = "#BDBDC3",
                        weight = 1,
                        popup = state_popup,
                        highlight = highlightOptions(
                            weight = 5,
                            color = "#666",
                            dashArray = "",
                            fillOpacity = 0.7,
                            bringToFront = TRUE))})


    observeEvent(input$Map_shape_click, { # update the location selectInput on map clicks
        p <- input$Map_shape_click
        if(!is.null(p$admin)){
            if(is.null(input$Business) || input$Business!=p$admin) updateSelectInput(session, "Business", selected=p$admin)
        }
    })
}


# Run the application
shinyApp(ui = ui, server = server)
CedricMondy/afbBNVD documentation built on May 8, 2019, 9:53 p.m.