R Shiny Shipping Logistics: How Shiny Provides Value to Your Business
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
R Shiny is a go-to technology when making apps and dashboards for companies using the R programming language. Shiny helps solve problems in complex business areas with large datasets, such as agriculture and life sciences. It’s also used extensively in business workflows from supply chain management to improving the process of shipping logistics.
Today you’ll get some insights into this line of work and an understanding of how the technology can help your business optimize shipping logistics with R Shiny. But first, let’s discuss why this is considered a complex problem.
Is your team limited by Excel? Explore two popular Excel alternatives for your data needs: Power BI vs R Shiny.
Table of contents:
- What is Shipping Logistics and What Makes it Complex?
- What is R Shiny?
- R Shiny Shipping Logistics – How to Get Started
- Summing up
What is shipping logistics and what makes it complex?
The term shipping logistics encompasses inbound and outbound logistics involved in product transportation. Many factors impact your strategy around shipping logistics, such as procurement, freight shipping, and carrier partnerships. Inventory locations are also a crucial point, as storing the majority of your inventory close to where most of your customers live will allow you faster, and almost headache-free shipping logistics.
Why is this important?
Well, according to Avionos 2020 B2C buyer report, 70% of shoppers view a clear and easy shipping experience as their top priority when shopping. This is why it’s essential to have an optimized shipping strategy that meets customers’ goals and expectations.
There are several ways you can optimize your shipping logistics process. We’ll only list a couple of them here, and for a full list and detailed explanations, please refer to the links in the reference section:
- Inventory distribution – A distributed inventory model enables you to reduce shipping costs and delivery times by storing the bulk of your products close to your customers in more than one fulfillment center.
- Order management automation – The process of order management begins when the customer places an order on your site and finishes when the customer receives the delivery. Inventory management software allows you to track orders and shipments easily as your store grows.
- Warehouse management system – A good WMS allows you to connect to your merchant dashboard, which then allows you to monitor and control daily warehouse operations, have better order efficiency, and much more.
What makes shipping logistics a complex line of business?
It’s easy to be a customer in 2023. Pretty much every store you go to has an online presence, which eliminates the need to go into the store physically. In addition, online stores generally have a richer product palette available.
But is it easy to be a business with an online store these days? Well, not so much.
With everything that’s been going on in the world in the last couple of years, shipping has faced its fair share of challenges. These include growing freight costs, continuously increasing customer expectations, and the general problem of labor shortage – just to name a few.
As a business, you need to stay one step (or a couple) ahead, and that’s where R Shiny chimes in. Up next, we’ll give you an idea behind R and Shiny, and then we’ll see how R Shiny can help you optimize shipping logistics.
What is R Shiny?
Building web applications and dashboards is no small task. Typically, this involves a deep understanding of frontend technologies, such as HTML, CSS, JavaScript, React/Angular/Vue, and also a working knowledge of backend technologies. Now, the backend can be written in pretty much any programming language, such as JavaScript, Python, or Go, but it also assumes you know how to work in language-specific backend frameworks. Long story short, it’s a lot of work.
R Shiny takes a different approach. It’s an R package that allows you to create interactive web applications directly in R, and it takes care of both the frontend and backend. The package was first released more than 10 years ago (2012) and is now used for fast prototyping and developing enterprise-grade applications across most industries.
If you know R and have a background in shipping logistics, no one is stopping you from creating custom-tailored apps that will address all the pain points from the field. We’ll talk more about this in the following section, but first, let’s see some beautiful examples of R Shiny dashboards.
R Shiny Dashboard Examples
Our curated collection of R Shiny Demo Apps showcases over 25 dashboards of different areas of interest, complexity levels, and development time (effort).
The one you see below was part of our Data for Good (D4G) initiative and was built in collaboration with the Institute of Dendrology of the Polish Academy of Sciences. It shows how different climate scenarios will affect European forests:
But probably the best example of how business-friendly R Shiny apps can get is our Shiny Enterprise Dashboard example. It implements custom-tailored UI features with a modern UI:
To conclude, R Shiny makes it easy for developers to write app prototypes in no time, but it also allows them to make these applications enterprise-worthy. Let’s see how to combine R Shiny and shipping logistics next.
Are you ready to use R Shiny? Download the Enterprise Dashboard template for free.
How to get started with R Shiny for your shipping logistics project
We’ve already discussed the complex problems that shipping logistics has to deal with, so now let’s see what R Shiny can do about it.
First, you need to know the problem(s) you’re aiming to solve. We’ll focus on only one: Inventory distribution. It is generic enough to give you an idea of how an R Shiny + shipping logistics combination might work, but also specific enough so you can see firsthand how to approach the integration.
Data quality is important. See a case study on how data validation saved clients real money.
Shipping logistics dataset
Let’s start by creating a dummy dataset – it will contain locations of imaginary customers from two Polish cities – Warsaw and Kraków. The following code snippet creates this dataset and spreads the customer around the city center location:
library(dplyr) library(shiny) library(leaflet) df_warsaw <- data.frame( city = "Warsaw", lat = runif(250, min = 52.230842 - 0.2, max = 52.230842 + 0.2), lon = runif(250, min = 21.017175 - 0.2, max = 21.017175 + 0.2) ) df_krakow <- data.frame( city = "Kraków", lat = runif(100, min = 50.066222 - 0.2, max = 50.066222 + 0.2), lon = runif(100, min = 19.954019 - 0.2, max = 19.954019 + 0.2) ) df <- bind_rows(list(df_warsaw, df_krakow)) df[sample(nrow(df), 10), ]
Leaflet customer map
Next, we can draw a Leaflet map showing customers as circular markers. Here’s an example that also centers the map around our data points:
map_centerpoint_lat <- (52.230842 + 50.066222) / 2 map_centerpoint_lon <- (21.017175 + 19.954019) / 2 leaflet() %>% setView(lat = map_centerpoint_lat, lng = map_centerpoint_lon, zoom = 6) %>% addProviderTiles("Esri.WorldStreetMap") %>% addCircleMarkers( data = df, radius = 5, color = "#0199f9", fillColor = "#0199f9", fillOpacity = 0.75 )
Are you new to Leaflet? This article will teach you how to make stunning geomaps in R.
So far, we only have a plain R implementation, and we haven’t actually discussed how our shipping logistics problem will be solved. We want to know the optimal location for inventory warehouses in both locations, and for simplicity’s sake let’s say it will be in the center of the customer cluster.
Our R Shiny shipping logistics application will implement the following:
- Sidebar controls – Allows you to choose locations from the list (currently only two locations).
- Leaflet map – Renders user locations and optimal warehouse location:
- Blue markers – Location of an individual user.
- Black marker – Optimal location for the inventory warehouse (just a center point).
Here’s an example implementation in code:
library(dplyr) library(shiny) library(leaflet) library(leaflegend) ################################################################################ # DATA CONFIGURATION ################################################################################ df_warsaw <- data.frame( city = "Warsaw", lat = runif(250, min = 52.230842 - 0.2, max = 52.230842 + 0.2), lon = runif(250, min = 21.017175 - 0.2, max = 21.017175 + 0.2) ) df_krakow <- data.frame( city = "Kraków", lat = runif(100, min = 50.066222 - 0.2, max = 50.066222 + 0.2), lon = runif(100, min = 19.954019 - 0.2, max = 19.954019 + 0.2) ) df <- bind_rows(list(df_warsaw, df_krakow)) map_centerpoint_lat <- (52.230842 + 50.066222) / 2 map_centerpoint_lon <- (21.017175 + 19.954019) / 2 ################################################################################ # SHINY APP ################################################################################ ui <- fluidPage( sidebarLayout( # Sidebar panel with the controls sidebarPanel = sidebarPanel( tags$h3("Customer locations"), tags$hr(), selectInput(inputId = "citySelect", label = "Choose locations:", choices = c("Warsaw", "Kraków"), selected = c("Warsaw", "Kraków"), multiple = TRUE) ), # Main panel with the map mainPanel = mainPanel( leafletOutput(outputId = "map") ) ) ) server <- function(input, output, session) { # Keep only the data for the selected location(s) data <- reactive({ df %>% filter(city %in% input$citySelect) }) # Calculate center points (optimal warehouse location) center_points <- reactive({ data() %>% group_by(city) %>% summarise(lat = mean(lat,), lon = mean(lon), .groups = "drop") %>% as.data.frame() }) # Map output$map <- renderLeaflet({ leaflet() %>% setView(lat = map_centerpoint_lat, lng = map_centerpoint_lon, zoom = 7) %>% addProviderTiles("Esri.WorldStreetMap") %>% addCircleMarkers( data = data(), radius = 5, color = "#0199f9", fillColor = "#0199f9", fillOpacity = 1 ) %>% # Dedicated markers for the center points addCircleMarkers( data = center_points(), radius = 8, color = "#000000", fillColor = "#000000", fillOpacity = 1 ) %>% # Custom legend addLegendFactor( pal = colorFactor(c("#0199f9", "#000000"), c("Customers", "Optimal Warehouse Location")), values = c("Customers", "Optimal Warehouse Location"), position = "bottomright", shape = "circle" ) }) } shinyApp(ui = ui, server = server)
Styling your Shiny shipping logistics app
R Shiny provides some basic stylings to the app, but these don’t look the best, especially with the map. You can declare your custom styles with CSS, so that’s what we’ll do next.
Create a CSS file in www/main.css
and paste the following inside it:
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap'); * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Poppins', sans-serif; } body { padding: 1rem; } #map { height: 98vh !important; border-radius: 0.5rem !important; }
Put simply, this snippet resets a couple of settings, sets a custom font, and adjusts the height of the map.
In app.R
(app file), you only need to add a single line of code inside ui
to include the CSS file:
ui <- fluidPage( tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "main.css")), sidebarLayout( ... ) )
Here’s what the dashboard looks like now:
There’s still a lot of work you can put into it, but it’s just enough to see how a simple shipping logistics problem can be solved with R Shiny.
Summing up R Shiny for shipping logistics
In today’s article, we’ve only scratched the surface of R Shiny shipping logistics. This area is both domain and company-specific, which means only you know the exact shipping logistics problem you need the solution for.
Also, it’s up to you to decide if you need a custom-tailored platform for your shipping logistics needs. If so, look no further than R Shiny – it has everything you need and will get you started in days or weeks, not months.
If you prefer to focus on the data and don’t want to write the code yourself, leave it to professionals. Reach out to Appsilon via the contact form below, and we’ll be happy to explore solutions for your team’s needs.
If scalability is on your mind, we built a Shiny app for 700 users and have a list of recommendations to speed up your Shiny apps.
References
- ShipBob: Shipping Logistics: Definition, Best Practices, & Guide
- CircuitBlog: A Complete Guide to Shipping Logistics in 2022
- Appsilon R Shiny Demo Gallery
The post appeared first on appsilon.com/blog/.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.