Logo

The Data Daily

Supply Chain Management Strategies with R and Shiny | R-bloggers

Supply Chain Management Strategies with R and Shiny | R-bloggers

Supply Chain Management Strategies with R and Shiny
Posted on October 20, 2022 by Eduardo Almeida in R bloggers | 0 Comments
[This article was first published on Tag: r - Appsilon | Enterprise R Shiny Dashboards , and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here )
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Share Tweet
During the pandemic, the supply chain and its management strategy burst into the spotlight. Supply chain management (SCM) became a household topic as its disruptions began to directly impact people’s lives and the global economy.
But the truth is, good supply chain strategies are the ones that are aligned with business strategy. And in this complex environment, there is a trade-off between responsive versus efficient strategies.
Sharing results using R Shiny
Spreadsheets, R, and Supply Chain Management
A spreadsheet solution enables a lot of flexibility but it comes at the expense of reproducibility and error pruning. ERP is a very mature system and has strict rules that make it reliable and efficient but adds little opportunity for newer designs.
This is an extreme example, but it’s a valid one:
Where IT products are not flexible enough nor have the required development speed for business needs, having spreadsheet solutions where an IT product should be used is a common source of strategy misalignment. And one that causes visibility issues in the supply chain.
This is where R comes into play. It’s great for solutions that require a certain degree of development speed and flexible design but are also reproducible with the building blocks of IT maturity. Knowing the requirements that allow an R solution to shine also depends on a proper understanding of where you stand with IT requirements and the business environment.
In this post, we depict the general understanding of business strategy and supply chain as a subsidy to strategic alignment and why using R sustains the visibility and reproducibility required for SCM strategy.
We’ll also show use cases for R and Shiny in SCM and how to add additional value. 
Strategy and the Supply Chain
Porter has a great definition of strategy: “the creation of fit between activities, where each activity is consistent, mutually reinforcing, and the fit is done optimally for competitive advantage.”
This fit can have different perspectives such as:
Internal fit: Organization structure
External fit: Competition
Dynamic fit: Demand behavior 
Also, Shapiro and Heskett state that strategy has a set of dichotomies that creates tension on each perspective, therefore, strategy decisions will always inherit a set of trade-offs.
This is an extensive field, and for this post, this is an essential concept. If you want to go further, I highly recommend Wharton’s free  Strategic Management program .
Supply Chain Overview
The supply chain is a big topic and can be explained through a variety of viewpoints. Below is a condensed summary of the SCOR Model and other descriptions. 
An additional summation:
Strategic fit in the Supply Chain
A strategic fit occurs when the competitive strategy and supply chain strategy align goals. Its success is connected to several factors:
Adjustment between the competitive strategy and functional supply chain strategies
Proper design of the processes and resources of different functions
Alignment between supply chain design and the role of each stage
A company can fail because of a lack of strategic fit or because the overall design, supply chain processes, and resources do not provide enough to support the desired strategic outcome.
There are three basic steps to achieve this and overcome potential failure:
Understand client uncertainty
Understand the supply chain capacities
Implement/Set the strategic fit
In summary, these steps ensure that there is an appropriate supply chain strategy for each product/service. And functional products have an efficient supply chain strategy while innovative products should fit with a responsive supply chain design. This is called the zone of strategic fit.
Staying competitive
It is important to note that products have a lifecycle, and the supply chain should account for that. Also, the real world is a dynamic system. That’s why alignment with the business strategy is important. It ensures the correct approach under each state of change.
Being able to understand what the drivers of change are and leverage them is what makes supply chain a field of both science and art. This means your supply chain strategy should leverage the theory, but also be fine-tuned for unique situations.
Therefore, using analytic solutions that can leverage both real data and theory into actionable insights provides huge value for supply chain strategists. Reproducibility is a key factor of success because it enhances visibility and enforces alignment between the scope of strategy and operations, as well as maintains sustainability .
For further studies on the supply chain, audit the free MITx program . 
R and Supply Chain Models
When we’re abstracting a model or testing a specific problem, using spreadsheets seems a great way to get the work done. Because it is at its core, flexible. But, in this situation, it’s can be difficult to explain the solution to others and make sure that the appropriate workflow is being followed.
Another drawback of spreadsheets is complex logic. When it comes to more complex problems it becomes harder to set the appropriate logic to design the solution in a steady state. Whereas in R, you can leverage a set of best practices and cutting-edge solutions from packages that are maintained by CRAN. This extends the level of quality that R grants to its users.
Note: CRAN is not without its risks. To ensure your project remains secure, you should explore the Isoband Incident and how to mitigate risks .
SCM in spreadsheets vs R example
Let’s take a look at an example by comparing the two solutions: spreadsheets vs R.
For each of the metrics in the data, you are asked to calculate the change in the sum of all countries in the ongoing previous month and previous year against the current one:
The concept is straightforward, we basically have to:
Group the data by date and sum each metric to account for all countries
Calculate the lag from the ongoing previous month and previous year
Calculate the difference between the lagged previous month/year and the current date.
To do this in spreadsheets, there are many approaches you could work on. One such example:
In this example, we can see that on the 1st of January 2016 56 items were produced while on the 1st of December 2015 it produced 80 items. This is a change in production by -24 items. The same logic applies to the year metric.
The data transformation that was asked for is complete. So what’s the issue then?
Reproducibility with spreadsheets
Basically, this approach adds too many manual insertions and each calculation must be checked and updated by the user. There is also the risk of mixing different cells in the calculation, this is the reproducibility problem.
Let’s not forget that we also need 6 other metrics on the data; the same approach is to be repeated 6 times in the spreadsheet.
Imagine for instance that data changes or another metric should be included later on. You will soon enter the spreadsheet productivity dilemma. It was fast to design, became hard to maintain, and now is harder to keep adding features. Soon enough, most of your daily work will revolve around spreadsheet issues instead of focusing on business value.
For the business strategy, this is also a problem. Because it compromises the overall strategy, especially in the supply chain regarding information flow. This issue, therefore, impacts the physical and financial flow. It also makes it harder for businesses to quickly detect changes in the supply chain.
This example is a rather common issue in business. Even beautifully designed dashboards sometimes source an entangled web of spreadsheet data transformations that are connected in non obvious ways and are very hard to understand the data pipeline.
R solution to the reproducibility problem
This same problem can be solved in R, in a very elegant solution provided by the tidyverse package:
cols % summarise(across(all_of(cols), sum, .names = "{col}")) %>% mutate( across( all_of(cols), list( prev_month = ~ lag(.x, n = 30), change_prev_month = ~ .x - lag(.x, n = 30), prev_year = ~ lag(.x, n = 365), change_prev_year = ~ .x - lag(.x, n = 365) ), .names = "{col}.{fn}" ) )
In this example, we can see that all the required steps for this data transformation are kept in the code. This means that understanding and debugging the applications is much easier and faster. And if anything changes in the source, it has a steady-state structure that can be easily updated. 
But R does not only allow you to make reproducible pipelines for dashboards as in the example above. It also allows you to create beautiful dashboards to share this data in a more consumable fashion. With R, you can create a new set of value by designing apps for specific problems – all without needing the skills of a web developer. 
We’ll show you how with a solution for the use case scenario below.
Supply Chain Management in R use case
Let’s start by presenting a very traditional supply chain design problem as the multiple-commodity transshipment problem.
In this problem, you minimize the total cost of fulfilling the demand for a set of products at each point of sales, while sharing capacity constraints on plants and distribution centers.
Data
For this problem, we have a template-ready dataset from a spreadsheet, this will have the following structure:
Node: Set of each entity of the model with their names
Flow cost: The cost related to sending each product to plant x DC and DC x region
Capacity: The total capacity of the Plants and DCs
Node Arcs: The demand per region/product and capacity of production of each plant/product
path % purrr::set_names() %>% purrr::map(readxl::read_excel, path = path)
To run the model, we must set it to the appropriate structure of R for optimization, this requires a set of data wrangling:
transship_wrang

Images Powered by Shutterstock