Deploying a basic Streamlit app using Shiny package in R
Last Updated :
24 Apr, 2025
In this article, we will be discussing the steps to deploy a basic Streamlit app using the Shiny package in R. Streamlit is a Python library that allows you to build interactive web applications for machine learning and data science. Shiny is an R package that allows you to build interactive web applications for data science. By combining these two packages, we can build a powerful interactive web application for data science in R. This is particularly useful for data scientists and machine learning engineers who work with R and want to build interactive web applications for their models and data visualizations. In this article, we will go through the installation of the required packages, creating a new R script, building the UI, and server logic, and running the app. We will also provide some examples to demonstrate the usage of Streamlit and Shiny in real-world applications.
Example of Streamlit app using Shiny package in R
A basic understanding of the Streamlit and Shiny packages is necessary to understand how they are used to create interactive web applications and how they differ. This includes knowledge of the different functions and features provided by each package and how they are used to create user interfaces, handle user input, and display output.
- Installing Required Packages
- Creating the UI of the App
- Creating the Server Logic
- Running the App
A Simple Calculator App
In this example, we create a Shiny app with a calculator. A simple calculator app interface that takes two numbers and operations from the user and on submission it displays the result.
R
library(streamlit)
library(shiny)
# UI
ui <- fluidPage(
textInput("num1", "Enter a number"),
textInput("num2", "Enter another number"),
selectInput("operation", "Select an operation", c("+", "-", "*", "/")),
actionButton("submit", "Calculate"),
textOutput("result")
)
# Server Logic
server <- function(input, output) {
observeEvent(input$submit, {
num1 <- as.numeric(input$num1)
num2 <- as.numeric(input$num2)
operation <- input$operation
if (operation == "+") {
result <- num1 + num2
} else if (operation == "-") {
result <- num1 - num2
} else if (operation == "*") {
result <- num1 * num2
} else {
result <- num1 / num2
}
output$result <- renderText({
paste0("The result is: ", result)
})
})
}
shinyApp(ui = ui, server = server)
Output:
Â
 Shiny App with a Plot
here, we create a Shiny app with a plot. The plot is created using the 'plot' function from the base R package and displayed on the app using the 'plotOutput' function. The plot displays the relationship between weight and miles per gallon for the cars in the 'mtcars' dataset.
R
library(shiny)
ui <- fluidPage(
plotOutput("plot")
)
server <- function(input, output) {
output$plot <- renderPlot({
plot(mtcars$wt, mtcars$mpg, xlab = "Weight", ylab = "MPG",
main = "Scatter Plot")
})
}
shinyApp(ui = ui, server = server)
Output:
 A Shiny App with a Table
In this example, we show how to create a Shiny app with a table. The table is created using the 'renderTable' function and displays the first six rows of the 'mtcars' dataset.
R
library(shiny)
ui <- fluidPage(
tableOutput("table")
)
server <- function(input, output) {
output$table <- renderTable({
head(mtcars)
})
}
shinyApp(ui = ui, server = server)
Output:
 A Shiny App with Input and Output
Here, we create a Shiny app with both input and output. The app has a single text input, where the user can enter a text value. The entered text is then displayed on the app using the 'textOutput' function.
R
library(shiny)
ui <- fluidPage(
textInput("text", "Text Input"),
textOutput("output")
)
server <- function(input, output) {
output$output <- renderText({
paste("You entered:", input$text)
})
}
shinyApp(ui = ui, server = server)
Output:
 A Shiny App with Multiple Inputs and Outputs
In this example, we create a Shiny app with multiple inputs and outputs. The app has two sliders, one for the number of observations and one for the standard deviation. The app then generates a random normal distribution based on the user's inputs and displays the histogram and summary statistics of the generated data.
R
library(shiny)
ui <- fluidPage(
titlePanel("Multiple Inputs and Outputs"),
sidebarLayout(
sidebarPanel(
sliderInput("obs", "Number of Observations:", min = 1,
max = 100, value = 50),
sliderInput("sd", "Standard Deviation:", min = 0,
max = 10, value = 2)
),
mainPanel(
plotOutput("distPlot"),
verbatimTextOutput("summary")
)
)
)
server <- function(input, output) {
data <- reactive({
rnorm(input$obs, mean = 0, sd = input$sd)
})
output$distPlot <- renderPlot({
hist(data(), main = "Histogram of Random Normal Distribution")
})
output$summary <- renderPrint({
summary(data())
})
}
shinyApp(ui, server)
Output:
Â
Similar Reads
Create An Interactive Web App Using Shiny Package In R
Perhaps a quick introduction to what Shiny is would be helpful before moving on. Creating interactive web applications with R Programming Language is simple thanks to the Shiny package. Shiny's advantage is that it enables you to extend your R code to the web, which essentially increases the usabili
4 min read
Create Interactive Dashboard in Python using Streamlit
An interactive and Informative dashboard is very necessary for better understanding our data sets. This will help a researcher for getting a better understanding of our results and after that, a researcher can make some necessary changes for better understanding. Visual Reports is must better than i
6 min read
Create Dynamic checkboxGroupInput in Shiny package Using R
The Shiny is an R package that allows us to build interactive web applications with R Programming Language. One of the core components of a Shiny app is the ability to dynamically update the content of the app based on user input. One way to do this is by using the checkboxGroupInput.which allows us
3 min read
Hide Certain Columns in a Responsive Data Table Using DT Package in R
The DT package in R Shiny provides a powerful and interactive way to display data tables in web applications. One useful feature is the ability to hide certain columns based on user interactions or display requirements. In this guide, weâll explore how to hide columns in a responsive data table usin
3 min read
How Do You Pass Parameters to a Shiny App via URL in R
Shiny is an R package that makes it easy to build interactive web applications. Sometimes, you might want to pass information to your Shiny app through the URL so that the app can react to or use this information. This can be useful if you want to customize the app based on the URL or share specific
2 min read
Change the Color and Font of Text in Shiny App in R
Shiny is an R package that provides tools for the creation of web applications (apps) directly in R, and the ability to select the color and font of text in Shiny apps can greatly improve the appearance of such apps. This article is going to help you understand how to change the color and font of te
4 min read
Change Color Scheme of ggplot2 Plot Using ggthemr Package in R
The open-source tool ggplot2 in R is used for statistical data visualization. To make the plots made by ggplot2 more appealing and to apply colors, different designs, and styling ggthemr Package in R is a great help. ggthemr Package in R Programming Language is developed by Ciarán Tobin and maintain
4 min read
Building REST API using R Programming
REST(Representational state transfer) API is an architectural style that includes specific constraints for building APIs to ensure that they are consistent, efficient, and scalable. REST API is a collection of syntax and constraints which are used in the development and operation of web services tha
3 min read
How to create a scatter plot using lattice package in R?
In this article, we will discuss how to create the scatter plots using lattice package in R programming language. In R programming, the Lattice package is a data visualization library that consists of various functions to plot different kinds of plots. Using the lattice library we can able to plot v
2 min read
How to create a boxplots using lattice package in R?
In this article, we will discuss how to create the boxplots using lattice package in R Programming language. In R programming, Lattice package is a data visualization library and consists of various functions to plot different kind of plots. Using lattice library we can able to plot different plots
2 min read