Building Interactive Web Applications in R
2023-04-07
Introduction to Shiny
Shiny architecture
Creating a simple Shiny app
Advanced features
Summary and Q&A
Shiny is an open-source R package developed by RStudio that allows developers to build interactive web apps straight from R.
It simplifies the process of integrating R code with HTML.
It doesn’t require knowledge of HTML or JavaScript, although such knowledge can enhance customization.
Shiny apps consist of two main components: the UI (User Interface) and the server.
The UI defines the layout and appearance of the app.
The server contains the instructions required to build the app.
Creating a Simple Shiny App - UI
fluidPage()
: creates a new page that automatically adjusts its layout to the browser’s dimensions.
titlePanel()
: sets the title.
sidebarLayout()
, sidebarPanel()
: create a sidebar.
sliderInput()
: creates an interactive slider.
Creating a Simple Shiny App - Server
server
: This function contains the processing logic of the app.
output$distPlot
: The output object is modified to include a plot named distPlot
.
renderPlot()
: This function is used to render the plot.
hist(rnorm(input$obs))
: Generate a histogram based on the input value from the slider.
shinyApp()
: This function takes the UI and server to start the Shiny app.Reactivity: One of the key features of Shiny is its built-in reactivity. This means when an input changes, the output changes automatically in response.
Widgets: Shiny includes a variety of widgets for inputs like checkboxes, sliders, and more.
Customization: With knowledge of HTML, CSS, and JavaScript, you can customize the appearance and functionality of your Shiny app far beyond the basic capabilities.
Shiny is a powerful tool for creating interactive web applications using R.
Shiny apps have two components, a UI and a server.
Reactive programming in Shiny allows for automatic updates when inputs change.
Now that we’ve covered the basics of Shiny and how to create an app, let’s open the floor for discussion.
Any queries, doubts, or ideas you’d like to share or discuss? Let’s dive into it!