Shiny Basics-Introduction

[This article was first published on finnstats », 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.

Story 492455589

Shiny Basics, you will learn two standards for constructing a simple Shiny application in this tutorial.

You’ll also learn how the program is structured, the components of the user interface, and where to put application logic.

How to Calculate Root Mean Square Error (RMSE) in R »

Shiny Basics

To summarise, a Shiny application consists of two major components.

The first component is the user interface, or UI, which is a web page that shows the information. It is composed of HTML components that you design with Shiny functions.

The Server is the second component. This is the location of the application logic.

Let’s make a simple Shiny application.

Here is the basic structure and to run a Shiny application. This script’s name is app.R, but you can call it whatever you like.

How to Measure Heteroscedasticity in Regression? »

Call shinyApp() in the final line of code, passing in the empty UI and server variables.

With the presence of the shinyApp() function in your code, the Run command transforms to Run App.

You can now launch the app by clicking the Run App button.

The console will have some output at this stage.

When you press the Run App button, the runApp() method is invoked. The app’s link will appear below it.

Stopping the app is as simple as clicking the Stop button.

It is important to note that the runApp() function should not be placed within the Shiny code.

Another method for creating a Shiny application is to split the UI and server code into two different files.

This is the preferred method for writing Shiny apps as they become more complicated.

How to Calculate Mean Absolute Percentage Error (MAPE) in R »

The server-side application logic code is written in a file called server.R, and the UI-specific code is written in a file called ui.R.

It is important to note that a call to shinyApp() is not required at the conclusion of either the server.R or ui.R files.

The ui.R and server.R files must be combined into a single folder.

When RStudio sees the two files combined, it recognizes them as a Shiny application.

Panel functions are used to arrange UI elements into a single panel.

For example, if you want text input and numeric input boxes on the side, you can put them in a sidebar panel.

Log Rank Test in R-Survival Curve Comparison »

Shiny Panels

Here is a list of panels that are currently available.

Panel routines return HTML div tags with certain bootstrap class characteristics.

Shiny Layout

In the application layout, you use the Layout methods to organize panels containing UI elements.

Here are several examples:

The fluidRow() function generates a fluid page layout consisting of rows and columns.

Rows ensure that all of their items are on the same line (if the browser has adequate width.)

Columns specify how much horizontal space its items should occupy inside a 12-unit wide grid. Fluid pages automatically scale their components to span the entire browser width.

The flowLayout() function arranges components from left to right and top to bottom. The sidebarLayout() function arranges items in a layout that includes a sidebar and a main section.

By default, the splitLayout() function arranges elements horizontally, splitting the available horizontal space into equal parts.

The verticalLayout() function, on the other hand, produces a container with one or more rows of content.

Control widgets are web elements with which users can interact. They enable users to provide input to the Server, which then executes the logic.

How to Remove Duplicates in R with Example »

When the user changes the widget values, the output matching to the input is also changed.

The Shiny package has a plethora of pre-built widget functions, which not only makes it easier to construct widgets but also improves their appearance.

Date input, file input, slider input, and more examples are provided. When input widgets update, the Server executes the logic and sends the result back to the corresponding UI output components.

Assume you have a program that computes the square of a number. Numeric input and output UI components are required.

You can transfer data to the server using the numeric input widget in the UI. The Server will compute the square of the input and return the result to the UI output element as shown.

You learned in this video that there are two standards for developing Shiny application files: a single file or two files named server.R and ui.R in a single folder.

You also learned about the UI components, including HTML tags, layouts, and widgets, as well as how the UI elements interact with the application logic.

How to Perform Dunnett’s Test in R » Post-hoc Test »

The post Shiny Basics-Introduction appeared first on finnstats.

To leave a comment for the author, please follow the link and comment on their blog: finnstats ».

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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)