R Shiny Shipping Logistics: How Shiny Provides Value to Your Business

Reading time:
time
min
By:
Dario Radečić
February 1, 2023

R Shiny is a go-to technology when making apps and dashboards for companies using the R programming language. <strong>Shiny helps solve problems in complex business areas</strong> with large datasets, such as <a href="https://appsilon.com/r-shiny-in-agriculture-examples/" target="_blank" rel="noopener">agriculture</a> and <a href="https://appsilon.com/r-shiny-in-life-sciences-examples/" target="_blank" rel="noopener">life sciences</a>. It's also used extensively in business workflows from <a href="https://appsilon.com/supply-chain-management-with-r-shiny/" target="_blank" rel="noopener">supply chain management</a> to <strong>improving the process of shipping logistics</strong>. 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. <blockquote>Is your team limited by Excel? Explore two popular Excel alternatives for your data needs: <a href="https://appsilon.com/powerbi-vs-r-shiny/" target="_blank" rel="noopener">Power BI vs R Shiny</a>.</blockquote> Table of contents: <ul><li><a href="#what-is-shipping-logistics">What is Shipping Logistics and What Makes it Complex?</a></li><li><a href="#what-is-r-shiny">What is R Shiny?</a></li><li><a href="#combining">R Shiny Shipping Logistics - How to Get Started</a></li><li><a href="#summary">Summing up</a></li></ul> <hr /> <h2 id="what-is-shipping-logistics">What is shipping logistics and what makes it complex?</h2> The term <b>shipping logistics</b> 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 <a href="https://www.avionos.com/wp-content/uploads/2020/06/2020-B2C-Report-Final-Who-Wins-Where.pdf" target="_blank" rel="nofollow noopener">Avionos 2020 B2C buyer report</a>, 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. <img class="size-full wp-image-17305" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b2abb2e8ea1473e19b7a34_1.webp" alt="Image 1 - Shipping containers (Photo by CHUTTERSNAP on Unsplash)" width="2400" height="1600" /> Image 1 - Shipping containers (Photo by <a href="https://unsplash.com/@chuttersnap?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">CHUTTERSNAP</a> on <a href="https://unsplash.com/photos/9cCeS9Sg6nU?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>) 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 <a href="#references">reference section</a>: <ul><li><b>Inventory distribution</b> - 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.</li><li><b>Order management automation</b> - 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.</li><li><b>Warehouse management system</b> - 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.</li></ul> <h3>What makes shipping logistics a complex line of business?</h3> 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. <b>But is it easy to be a business with an online store these days?</b> 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. <h2 id="what-is-r-shiny">What is R Shiny?</h2> 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. <strong>R Shiny takes a different approach</strong>. 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. <h3>R Shiny Dashboard Examples</h3> Our curated collection of <a href="https://demo.appsilon.com" target="_blank" rel="noopener">R Shiny Demo Apps</a> showcases over 25 dashboards of different areas of interest, complexity levels, and development time (effort). The one you see below was part of our <a href="https://appsilon.com/data-for-good/" target="_blank" rel="noopener">Data for Good (D4G)</a> 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 <a href="https://connect.appsilon.com/future-forests/" target="_blank" rel="noopener">European forests</a>: <img class="size-full wp-image-17307" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b7d29e7d51e4abfae67405_66052cb1_2-1.webp" alt="Image 2 - Appsilons Future Forests dashboard example" width="1824" height="1447" /> Image 2 - Appsilons Future Forests dashboard example But probably the best example of how business-friendly R Shiny apps can get is our <a href="https://connect.appsilon.com/shiny-enterprise-demo/" target="_blank" rel="noopener">Shiny Enterprise Dashboard</a> example. It implements custom-tailored UI features with a modern UI: <img class="size-full wp-image-17309" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b7d29febc881cc383121ee_50d951a5_3-1.webp" alt="Image 3 - Appsilons Enterprise Dashboard example" width="1824" height="1447" /> Image 3 - Appsilons Enterprise Dashboard example 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? <a href="https://templates.appsilon.com/" target="_blank" rel="noopener">Download the Enterprise Dashboard template for free</a>. <h2 id="combining">How to get started with R Shiny for your shipping logistics project</h2> 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: <b>Inventory distribution</b>. 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. <blockquote>Data quality is important. <a href="https://appsilon.com/data-quality/" target="_blank" rel="noopener">See a case study on how data validation saved clients real money</a>.</blockquote> <h3>Shipping logistics dataset</h3> 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: <pre><code class="language-r">library(dplyr) library(shiny) library(leaflet) <br> df_warsaw &lt;- 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 &lt;- 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 &lt;- bind_rows(list(df_warsaw, df_krakow)) df[sample(nrow(df), 10), ]</code></pre> <img class="size-full wp-image-17311" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b7d29f0d37f908a0b27036_e0c85b62_4-1.webp" alt="Image 4 - 10-row sample of the dataset" width="374" height="359" /> Image 4 - 10-row sample of the dataset <h3>Leaflet customer map</h3> Next, we can draw a <a href="https://rstudio.github.io/leaflet/" target="_blank" rel="nofollow noopener">Leaflet map</a> showing customers as circular markers. Here's an example that also centers the map around our data points: <pre><code class="language-r">map_centerpoint_lat &lt;- (52.230842 + 50.066222) / 2 map_centerpoint_lon &lt;- (21.017175 + 19.954019) / 2 <br>leaflet() %&gt;%  setView(lat = map_centerpoint_lat, lng = map_centerpoint_lon, zoom = 6) %&gt;%  addProviderTiles("Esri.WorldStreetMap") %&gt;%  addCircleMarkers(    data = df,    radius = 5,    color = "#0199f9",    fillColor = "#0199f9",    fillOpacity = 0.75  )</code></pre> <img class="size-full wp-image-17313" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b7d2a0685aa739d61664ca_37f20142_5-1.webp" alt="Image 5 - Basic Leaflet map" width="1792" height="1333" /> Image 5 - Basic Leaflet map <blockquote>Are you new to Leaflet? <a href="https://appsilon.com/leaflet-geomaps/" target="_blank" rel="noopener">This article will teach you how to make stunning geomaps in R</a>.</blockquote> 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: <ul><li><b>Sidebar controls</b> - Allows you to choose locations from the list (currently only two locations).</li><li><b>Leaflet map</b> - Renders user locations and optimal warehouse location:<ul><li>Blue markers - Location of an individual user.</li><li>Black marker - Optimal location for the inventory warehouse (just a center point).</li></ul> </li> </ul> Here's an example implementation in code: <pre><code class="language-r">library(dplyr) library(shiny) library(leaflet) library(leaflegend) <br>################################################################################ # DATA CONFIGURATION ################################################################################ df_warsaw &lt;- 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 &lt;- 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 &lt;- bind_rows(list(df_warsaw, df_krakow)) map_centerpoint_lat &lt;- (52.230842 + 50.066222) / 2 map_centerpoint_lon &lt;- (21.017175 + 19.954019) / 2 <br> ################################################################################ # SHINY APP ################################################################################ ui &lt;- 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")    )  ) ) <br>server &lt;- function(input, output, session) {  # Keep only the data for the selected location(s)  data &lt;- reactive({    df %&gt;%      filter(city %in% input$citySelect)  })    # Calculate center points (optimal warehouse location)  center_points &lt;- reactive({    data() %&gt;%      group_by(city) %&gt;%      summarise(lat = mean(lat,), lon = mean(lon), .groups = "drop") %&gt;%      as.data.frame()  })    # Map  output$map &lt;- renderLeaflet({    leaflet() %&gt;%      setView(lat = map_centerpoint_lat, lng = map_centerpoint_lon, zoom = 7) %&gt;%      addProviderTiles("Esri.WorldStreetMap") %&gt;%      addCircleMarkers(        data = data(),        radius = 5,        color = "#0199f9",        fillColor = "#0199f9",        fillOpacity = 1      ) %&gt;%      # Dedicated markers for the center points      addCircleMarkers(        data = center_points(),        radius = 8,        color = "#000000",        fillColor = "#000000",        fillOpacity = 1      ) %&gt;%      # Custom legend      addLegendFactor(        pal = colorFactor(c("#0199f9", "#000000"), c("Customers", "Optimal Warehouse Location")),        values = c("Customers", "Optimal Warehouse Location"),        position = "bottomright",        shape = "circle"      )  }) } <br>shinyApp(ui = ui, server = server)</code></pre> <img class="size-full wp-image-17315" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b7d2a171479ae649265c2b_286d4cc3_6-1.webp" alt="Image 6 - Shiny application" width="1745" height="1172" /> Image 6 - Shiny application <h3>Styling your Shiny shipping logistics app</h3> 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 <code>www/main.css</code> and paste the following inside it: <pre><code class="language-css">@import url('https://fonts.googleapis.com/css2?family=Poppins&amp;display=swap'); <br>* {  margin: 0;  padding: 0;  box-sizing: border-box;  font-family: 'Poppins', sans-serif; } <br>body {  padding: 1rem; } <br>#map {  height: 98vh !important;  border-radius: 0.5rem !important; }</code></pre> Put simply, this snippet resets a couple of settings, sets a custom font, and adjusts the height of the map. In <code>app.R</code> (app file), you only need to add a single line of code inside <code>ui</code> to include the CSS file: <pre><code class="language-r">ui &lt;- fluidPage(  tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "main.css")),  sidebarLayout(    ...  ) )</code></pre> Here's what the dashboard looks like now: <img class="size-full wp-image-17317" src="https://wordpress.appsilon.com/wp-content/uploads/2023/01/7.gif" alt="Image 7 - Finished dashboard" width="1912" height="1324" /> Image 7 - Finished dashboard 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. <hr /> <h2 id="summary">Summing up R Shiny for shipping logistics</h2> 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. <b>Reach out to Appsilon via the contact form below</b>, and we'll be happy to explore solutions for your team's needs. If scalability is on your mind, we built a <a href="https://appsilon.com/how-we-built-a-shiny-app-for-700-users/" target="_blank" rel="noopener">Shiny app for 700 users</a> and have a <a href="https://appsilon.com/speeding-up-r-shiny/" target="_blank" rel="noopener">list of recommendations to speed up your Shiny apps</a>. <h3 id="references">References</h3><ul><li><a href="https://www.shipbob.com/blog/shipping-logistics/" target="_blank" rel="nofollow noopener">ShipBob: Shipping Logistics: Definition, Best Practices, &amp; Guide</a></li><li><a href="https://getcircuit.com/teams/blog/guide-to-shipping-logistics" target="_blank" rel="nofollow noopener">CircuitBlog: A Complete Guide to Shipping Logistics in 2022</a></li><li><a href="https://demo.appsilon.com" target="_blank" rel="noopener">Appsilon R Shiny Demo Gallery</a></li></ul>

Have questions or insights?

Engage with experts, share ideas and take your data journey to the next level!
Explore Possibilities

Share Your Data Goals with Us

From advanced analytics to platform development and pharma consulting, we craft solutions tailored to your needs.

Talk to our Experts
r
shiny
community