Branches of mechanical engineering: Edifice Shiny App Exercises + Solutions - Business Office Ane - R





INTRODUCTION TO SHINY
Shiny is a parcel from RStudio that tin ship away endure used to laid upward interactive spider web pages amongst RStudio which is is an opened upward source laid of integrated tools designed to aid you lot endure to a greater extent than productive amongst R as well as you lot tin ship away download it from here. Use the examples inwards this tutorial to “take a outset bite” as well as laid upward for the exercises that follow as well as volition aid you lot laid upward your outset Shiny Application from “zero point”. This is the outset component division of the serial as well as nosotros volition only create the interface, brand some HTML formatting as well as add together an icon to our application. Specifically nosotros volition start creating a Shiny Application that volition analyze the famous (Fisher’s or Anderson’s) iris information laid which gives the measurements inwards centimeters of the variables sepal length as well as width as well as petal length as well as width, respectively, for l flowers from each of iii species of iris. The species are Iris setosa, versicolor, as well as virginica. Lets go!
BUILDING INTERFACE (UI)
Every Shiny application includes ii parts: a spider web page which shows the app to the user (UI), as well as a estimator that activates the app (server). You postulate to create these ii parts. UI is only a spider web document that the user gets to come across as well as is responsible for creating the layout of the app as well as telling Shiny precisely where things go. The server is responsible for the logic of the app.
You tin ship away create a Shiny app yesteryear making a novel directory as well as saving a ui.R as well as server.R file within it. Each app volition postulate its ain unique directory.
You tin ship away run a Shiny app yesteryear giving the cite of its directory to the function runApp(). For instance if your Shiny app is inwards a directory called “Shiny App”, run it amongst the next code:

library(shiny)
runApp("Shiny App")

Or yesteryear only clicking the “Run App” push at the overstep of the editor which is the safest solution.
Answers to the exercises are available here.
If you lot obtained a unlike (correct) response than those listed on the solutions page, delight experience gratis to post your response every bit a comment on that page.
Learn more about Shiny inwards the online course R Shiny Interactive Web Apps – Next Level Data Visualization. In this course of didactics you lot volition larn how to create advanced Shiny spider web apps; embed video, pdfs as well as images; add together focus as well as zooming tools; as well as many other functionalities (30 lectures, 3hrs.).
Exercise 1
Create a novel directory named “Shiny App” inwards your working directory.
Exercise 2
Create the ui.r as well as server.r files.
Secondly, nosotros cause got to install the “Shiny” parcel with:

install.packages("shiny")

as well as and hence nosotros volition telephone telephone it with:

library(shiny)

Now that nosotros analyzed the construction of a Shiny app, nosotros volition exhibit you lot how to laid upward a user-interface for this.
To acquire started, nosotros opened upward the server.R as well as ui.R files as well as edit them similar this:
#ui.R
shinyUI(fluidPage())
#server.R
shinyServer(function(input, output) {})
The trial is an empty app amongst a blank user-interface, only to start out with.
Exercise 3
Create an empty app amongst a blank user-interface.
LAYOUT
Shiny ui.R scripts utilization the function fluidPage() to create a display that automatically adjusts to the dimensions of your user’s browser window. You lay out your app yesteryear placing elements inwards the fluidPage()function.
For example, the ui.R script below creates a user-interface that has a championship panel as well as and hence a sidebar layout, which includes a sidebar panel as well as a master copy panel. Note that these elements are placed within the fluidPage() function.
#ui.R

shinyUI(fluidPage(
titlePanel("title panel"),
sidebarLayout(
sidebarPanel( "sidebar panel"),
mainPanel("main panel"))))

The TitlePanel() and sidebarLayout() are the ii most used elements to add together to fluidPage(). They create a basic Shiny app amongst a sidebar.
The sidebarLayout() always takes ii arguments: sidebarPanel component division output as well as mainPanel component division output.
Exercise 4
Create titlePanel(), cite it “Shiny App” and sidebarLayout(). Do non forget to add sidebarPanel() and mainPanel() inside this.
a.
Exercise 8
Add the championship “Analysis” nether the desciption paragraph of your mainPanel. Do non forget the comma separation. HINT: Use br and h2.
Exercise 9
Use bold text to the words “Iris setosa”,”versicolor” as well as “virginica”. HINT: Use strong.
IMAGES
Images tin ship away meliorate the appearance of your app as well as aid users empathise the content. Shiny uses img() function to seat icon files inwards your app. To insert an image, plough over the img() function the cite of your icon file every bit the src argument (e.g., img(src = "my_image.png")). You tin ship away also include other HTML parameters such as height and width. For example:

img(src = "my_image.png", elevation = 68, width = 68)
.
The img() function looks for your icon file inwards a specific place. Your file must endure inwards a folder named “www” inwards the same directory every bit the ui.R script. Shiny volition portion whatever file placed hither amongst your user’s spider web browser, which makes “www” a cracking house to seat images, mode sheets, as well as other things the browser volition postulate to laid upward the spider web components of your Shiny app. So if you lot desire to utilization an icon named “something.png”, your Shiny App directory should await similar this one:
#ui.R

shinyUI(fluidPage(
titlePanel("My Shiny App"),
sidebarLayout(
sidebarPanel(),
mainPanel(
img(src="something.png", elevation = 350, width = 350)))))
Exercise 10
Download this image as well as house it inwards a folder labeled “www” within your “Shiny App” directory. Name it “petal”, add together .jpg extension as well as and hence telephone telephone the img function within the sidebarPanel(). Use height and widthto create upward one's take away heed its dimensions.


________________________________________________
Below are the solutions to here.
If you lot obtained a unlike (correct) response than those listed on the solutions page, delight experience gratis to post your response every bit a comment on that page.
Learn more about Shiny inwards the online course R Shiny Interactive Web Apps – Next Level Data Visualization. In this course of didactics you lot volition larn how to create advanced Shiny spider web apps; embed video, pdfs as well as images; add together focus as well as zooming tools; as well as many other functionalities (30 lectures, 3hrs.).
Exercise 1
Create a novel directory named “Shiny App” inwards your working directory.
Exercise 2
Create the ui.r as well as server.r files.
Secondly, nosotros cause got to install the “Shiny” parcel with:

install.packages("shiny")

as well as and hence nosotros volition telephone telephone it with:

library(shiny)

Now that nosotros analyzed the construction of a Shiny app, nosotros volition exhibit you lot how to laid upward a user-interface for this.
To acquire started, nosotros opened upward the server.R as well as ui.R files as well as edit them similar this:
#ui.R
shinyUI(fluidPage())
#server.R
shinyServer(function(input, output) {})
The trial is an empty app amongst a blank user-interface, only to start out with.
Exercise 3
Create an empty app amongst a blank user-interface.
LAYOUT
Shiny ui.R scripts utilization the function fluidPage() to create a display that automatically adjusts to the dimensions of your user’s browser window. You lay out your app yesteryear placing elements inwards the fluidPage()function.
For example, the ui.R script below creates a user-interface that has a championship panel as well as and hence a sidebar layout, which includes a sidebar panel as well as a master copy panel. Note that these elements are placed within the fluidPage() function.
#ui.R

shinyUI(fluidPage(
titlePanel("title panel"),
sidebarLayout(
sidebarPanel( "sidebar panel"),
mainPanel("main panel"))))

The TitlePanel() and sidebarLayout() are the ii most used elements to add together to fluidPage(). They create a basic Shiny app amongst a sidebar.
The sidebarLayout() always takes ii arguments: sidebarPanel component division output as well as mainPanel component division output.
Exercise 4
Create titlePanel(), cite it “Shiny App” and sidebarLayout(). Do non forget to add sidebarPanel() and mainPanel() inside this.
), "data laid gives the measurements inwards centimeters of the variables sepal length as well as width as well as petal length as well as width, respectively, for l flowers from each of iii species of iris. The species are Iris setosa, versicolor, as well as virginica. ") ) ))) #################### # # # Exercise 8 # # # #################### ##ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu") ), mainPanel(h1("Main"), p("This famous (Fisher's or Anderson's)", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inwards centimeters of the variables sepal length as well as width as well as petal length as well as width, respectively, for l flowers from each of iii species of iris. The species are Iris setosa, versicolor, as well as virginica. "), br(), h2("Analysis") ) ))) #################### # # # Exercise ix # # # #################### ##ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu") ), mainPanel(h1("Main"), p("This famous (Fisher's or Anderson's)", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inwards centimeters of the variables sepal length as well as width as well as petal length as well as width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) ))) #################### # # # Exercise 10 # # # #################### ##ui.R library(shiny) shinyUI(fluidPage( titlePanel("Shiny App"), sidebarLayout( sidebarPanel(h2("Menu"), img(src = "petal.jpg", height = 72, width = 100) ), mainPanel(h1("Main"), p("This famous (Fisher's or Anderson's)", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html"), "data laid gives the measurements inwards centimeters of the variables sepal length as well as width as well as petal length as well as width, respectively, for l flowers from each of iii species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")), br(), h2("Analysis") ) )))

Source: 
http://www.r-exercises.com/2016/12/12/building-shiny-app-solutions-part-1/
http://www.r-exercises.com/2016/12/12/building-shiny-app-exercises-part-1/


Sumber http://engdashboard.blogspot.com/

Jangan sampai ketinggalan postingan-postingan terbaik dari Branches of mechanical engineering: Edifice Shiny App Exercises + Solutions - Business Office Ane - R. Berlangganan melalui email sekarang juga:

Bali Attractions

BACA JUGA LAINNYA:

Bali Attractions