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




RENDER FUNCTIONS
In the fourth part of our serial nosotros but “scratched the surface” of reactivity past times analyzing some of the properties of the renderTablefunction.
Now it is fourth dimension to acquire deeper as well as larn how to utilisation the residue of the homecoming functions that shiny provides. As you lot were told in part 4these are:
renderImage
renderPlot
renderPrint
renderText
renderUI
Below you lot volition come across the functionality of iii of them (renderImagerenderText and renderPrint) as well as thus nosotros volition hold upward cook to utilisation those of them that fit our needs inward the side past times side parts, but similar the widgets as well as hand a specific cast to our application. As you lot volition in all likelihood understand, when reading this component division our aim is to perform several statistical analyses on our dataset. We volition kickoff past times creating a K-Means tabPanel.
Follow the examples to sympathise the logic of the tools you lot are going to utilisation as well as thus heighten the app you lot started creating in part 1 by practising amongst the practise laid nosotros prepared for you. Lets begin!
Answers to the exercises are available here.
If you lot obtained a dissimilar (correct) response than those listed on the solutions page, delight experience gratis to postal service your response equally a comment on that page.
renderImage
Sending pre-rendered images with renderImage.
These are images saved equally a link to a source file. If your Shiny app has pre-rendered images saved inward a subdirectory, you lot tin hand the axe transportation them using renderImage. Suppose the images are inward the subdirectory “www”/, as well as are named “image1.png”, “image2.png”, as well as thus on. The next code would transportation the appropriate image, depending on the value of input$n:
# ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("RenderImage"),
sidebarLayout(
sidebarPanel(
radioButtons("n", label = h4("Radio Buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2),
selected = 2)
),
mainPanel(
imageOutput("Image")
)
)
))
#server.R
shinyServer(function(input, output, session) {
# Send a pre-rendered image, as well as don't delete the picture afterward sending it
output$Image <- renderImage({
# When input$n is 3, filename is ./images/image3.jpeg
filename <- normalizePath(file.path('./www',
paste('image', input$n, '.png', sep='')))
# Return a listing containining the filename
list(src = filename)
}, deleteFile = FALSE)
})
Now let’s suspension downward what the code inward a higher house precisely does. First of all equally nosotros saw in part 1 you should relieve your images inward a subdirectory called “www” within the directory that you lot work. Let’s tell you lot relieve 2 images as well as you lot advert them “image1” as well as “image2”. As you lot tin hand the axe come across nosotros use radioButtonshere to select which 1 of the 2 nosotros desire to hold upward displayed. The filename contains the exact output path of the images spell the list contains the filename along amongst another values.
In this example, deleteFile is FALSE because nosotros don’t desire Shiny to delete an picture afterward sending it.
Learn more about Shiny inward the online course R Shiny Interactive Web Apps – Next Level Data Visualization. In this course of report you lot volition larn how to do 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
Place a tabPanel in the tabsetPanel of your Shiny App. Name it “K Means”.
Exercise 2
Move the radioButtons from the sidebarPanel inside the tabPanel “K Means” you lot but created as well as advert it “Select Image”. Also, movement the submitButton from the sidebarPanel to the tabPanel “K Means” without title.
Exercise 3
Place an imageOutput inside the tabPanel “K Means” amongst advert “Image” (ui.R) as well as the reactive business office of it (server.R). Still zero happens. HINT: Use renderImage.
Create a subdirectory within the directory you lot piece of occupation as well as advert it “images”. Put at that topographic point 2 images amongst names “pic1” as well as “pic2” respectively as well as .png ending.
Exercise 4
Now do the filename. Follow the instance inward a higher house to do the right path. Do non forget to connect it amongst the radioButtons. Two steps left.
Exercise 5
Now it is fourth dimension to set deleteFile = “FALSE”.
Exercise 6
Create the list that contains the filename.
Exercise 7
Set width = 300 and height = 200 into the list.
renderText-renderPrint
The instance below shows how the renderText works.
#ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("RenderImage"),
sidebarLayout(
sidebarPanel(
sliderInput("slider1", label = h4("Sliders"),
min =3 , max = 10, value =3)
),
mainPanel(
textOutput("text1")
)
)
))

#server.R
shinyServer(function(input, output, session) {
output$text1 <- renderText({
paste(“You receive got selected”, input$slider1,”clusters”)
})
})
The code inward a higher house takes a numeric value from the sliderInput and puts it inward the exact house of our judgement inward the mainPanel.
Before proceeding to the side past times side practise movement the sliderInput from the sidebarPanel just afterward the imageOutput in the tabPanel “K Means”. Then alter its advert to “Clusters”, its min to 3, its max to 10 and value to 3.
Exercise 8
Put the textOutpout named “text1” within your tabPanel exactly afterward the sliderInput, thus house its reactive business office within server.R using renderText.
Exercise 9
Display the reactive output past times putting within the renderTextfunction the judgement “You receive got selected”,(?),”clusters.” HINT : Use paste.
Exercise 10
Follow precisely the same steps but this fourth dimension instead of renderText use renderPrint and banking venture complaint the difference.
___________________________________________________


Below are the solutions to these exercises on Building Shiny App.
#################### #                  # #    Exercise 1    # #                  # ####################  #ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                    column(6,                  h4("Submitbutton"),                  submitButton("Submit")),                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE)),                  column(6,                         radioButtons("radio", label = h4("Radio Buttons"),                                      choices = list("Choice 1" = 1, "Choice 2" = 2),                                      selected = 2))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6,                         sliderInput("slider1", label = h4("Sliders"),                                     min = 0, max = 100, value = c(10,90)))),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               p("This famous (Fisher's or Anderson's) ", a("iris",href="http://stat.ethz.ch/R-manual/R-devel/library/datasets/iris.html"), "data laid gives the measurements inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means"))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10)) })  #################### #                  # #    Exercise 2    # #                  # ####################  #ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6,                         sliderInput("slider1", label = h4("Sliders"),                                     min = 0, max = 100, value = c(10,90)))),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               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 inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means",                                                radioButtons("radio", label = h4("Select Image"),                                                             choices = list("Choice 1" = 1, "Choice 2" = 2),                                                             selected = 1),submitButton("Submit")))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))  })  #################### #                  # #    Exercise 3    # #                  # ####################  #ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6,                         sliderInput("slider1", label = h4("Sliders"),                                     min = 0, max = 100, value = c(10,90)))),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               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 inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means",                                                radioButtons("radio", label = h4("Select Image"),                                                             choices = list("Choice 1" = 1, "Choice 2" = 2),                                                             selected = 1), imageOutput("Image"),submitButton("Submit")))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   output$Image <- renderImage({}) })  #################### #                  # #    Exercise 4    # #                  # ####################  #ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6,                         sliderInput("slider1", label = h4("Sliders"),                                     min = 0, max = 100, value = c(10,90)))),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               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 inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means",                                                radioButtons("radio", label = h4("Select Image"),                                                             choices = list("Choice 1" = 1, "Choice 2" = 2),                                                             selected = 1), imageOutput("Image"),submitButton("Submit")))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   output$Image <- renderImage({     filename <- normalizePath(file.path('./images',                                         paste('pic', input$radio, '.png', sep='')))    }) }) #################### #                  # #    Exercise v    # #                  # ####################  #ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6,                         sliderInput("slider1", label = h4("Sliders"),                                     min = 0, max = 100, value = c(10,90)))),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               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 inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means",                                                radioButtons("radio", label = h4("Select Image"),                                                             choices = list("Choice 1" = 1, "Choice 2" = 2),                                                             selected = 1), imageOutput("Image"),submitButton("Submit")))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   output$Image <- renderImage({     filename <- normalizePath(file.path('./images',                                         paste('pic', input$radio, '.png', sep='')))    },deleteFile = FALSE) })  #################### #                  # #    Exercise six    # #                  # ####################  #ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6,                         sliderInput("slider1", label = h4("Sliders"),                                     min = 0, max = 100, value = c(10,90)))),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               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 inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means",                                                radioButtons("radio", label = h4("Select Image"),                                                             choices = list("Choice 1" = 1, "Choice 2" = 2),                                                             selected = 1), imageOutput("Image"),submitButton("Submit")))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   output$Image <- renderImage({     filename <- normalizePath(file.path('./images',                                         paste('pic', input$radio, '.png', sep='')))     list(src = filename)     },deleteFile = FALSE) })  #################### #                  # #    Exercise seven    # #                  # ####################  #ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6,                         sliderInput("slider1", label = h4("Sliders"),                                     min = 0, max = 100, value = c(10,90)))),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               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 inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means",                                                radioButtons("radio", label = h4("Select Image"),                                                             choices = list("Choice 1" = 1, "Choice 2" = 2),                                                             selected = 1), imageOutput("Image"),submitButton("Submit")))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   output$Image <- renderImage({     filename <- normalizePath(file.path('./images',                                         paste('pic', input$radio, '.png', sep='')))     list(src = filename,          width=300,          height=200)     },deleteFile = FALSE) })  #################### #                  # #    Exercise 8    # #                  # ####################  ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6                         )),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               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 inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means",                                                radioButtons("radio", label = h4("Select Image"),                                                             choices = list("Choice 1" = 1, "Choice 2" = 2),                                                             selected = 1), imageOutput("Image"),                                                sliderInput("slider1", label = h4("Clusters"),                                                            min = 3, max = 10, value = 3),                                                textOutput("text1"),                                                submitButton("Submit")))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   output$Image <- renderImage({     filename <- normalizePath(file.path('./images',                                         paste('pic', input$radio, '.png', sep='')))     list(src = filename,          width=300,          height=200)     },deleteFile = FALSE)   output$text1 <- renderText({}) })  #################### #                  # #    Exercise ix    # #                  # ####################  #ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6                         )),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               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 inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means",                                                radioButtons("radio", label = h4("Select Image"),                                                             choices = list("Choice 1" = 1, "Choice 2" = 2),                                                             selected = 1), imageOutput("Image"),                                                sliderInput("slider1", label = h4("Clusters"),                                                            min = 3, max = 10, value = 3),                                                textOutput("text1"),                                                submitButton("Submit")))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   output$Image <- renderImage({     filename <- normalizePath(file.path('./images',                                         paste('pic', input$radio, '.png', sep='')))     list(src = filename,          width=300,          height=200)     },deleteFile = FALSE)   output$text1 <- renderText({     paste("You receive got selected", input$slider1,"clusters")   }) })  #################### #                  # #    Exercise 10   # #                  # ####################  #ui.R library(shiny) shinyUI(fluidPage(   titlePanel("Shiny App"),    sidebarLayout(     sidebarPanel(h2("Menu"),                  br(),                  fluidRow(                    column(6,                  h4("Actionbutton"),                  actionButton("per", label = "Perform")),                    column(6,                  h4("Help Text"),                  helpText("Just for help"))),                  br(),                  fluidRow(                  column(6,                         numericInput("numer",                                      label = h4("Numeric Input"),                                      value = 10))),                  fluidRow(                    column(6,                  h4("Single Checkbox"),                  checkboxInput("checkbox", label = "Choice A", value = TRUE))),                  fluidRow(                    column(6,                  checkboxGroupInput("checkGroup",                                     label = h4("Checkbox group"),                                     choices = list("Choice 1" = 1,                                                    "Choice 2" = 2, "Choice 3" = 3),                                     selected = 2)),                   column(6,                         selectInput("select", label = h4("Select Box"),                                     choices = list("Choice 1" = 1, "Choice 2" = 2                                                   ), selected = 1))),                  fluidRow(                    column(6,                  dateInput("date",                            label = h4("Date input"),                            value = "2016-12-01")),                  column(6                         )),                  fluidRow(                    column(6,                  dateRangeInput("dates", label = h4("Date Range"))),                  column(6,                         textInput("text", label = h4("Text Input"),                                   value = "Some Text"))),                  fileInput("file", label = h4("File Input"))),     mainPanel(h1("Main"),               img(src = "petal.jpg", height = 150, width = 200),               br(),               br(),               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 inward 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 3 species of iris. The species are ",strong( "Iris setosa,"),strong( "versicolor"), "and", strong("virginica.")),               br(),               h2("Analysis"),               tabsetPanel(type="tabs",tabPanel("Data Table",dataTableOutput("Table")),                                       tabPanel("Summary"),                                       tabPanel("K means",                                                radioButtons("radio", label = h4("Select Image"),                                                             choices = list("Choice 1" = 1, "Choice 2" = 2),                                                             selected = 1), imageOutput("Image"),                                                sliderInput("slider1", label = h4("Clusters"),                                                            min = 3, max = 10, value = 3),                                                textOutput("text1"),                                                submitButton("Submit")))      )   )   )) #server.R shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   output$Image <- renderImage({     filename <- normalizePath(file.path('./images',                                         paste('pic', input$radio, '.png', sep='')))     list(src = filename,          width=300,          height=200)     },deleteFile = FALSE)   output$text1 <- renderPrint({     paste("You receive got selected", input$slider1,"clusters")   }) })

http://www.r-exercises.com/2017/01/24/building-shiny-app-exercises-part-5/
http://www.r-exercises.com/2017/01/24/building-shiny-app-solutions-part-5/

Sumber http://engdashboard.blogspot.com/

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

Bali Attractions

BACA JUGA LAINNYA:

Bali Attractions