How to use Shiny in Rstudio(1)

Background

Shiny is a web application developed by RStudio. The advantage of Shiny is that you could change your inputs easily and get the results simultaneously. Both input and output have multiple forms or functions. I start the learning path from the website http://shiny.rstudio.com/tutorial/. The baic coding templates of Shiny is:

Ui <- fluidPage()
Server<- function(input, output) {} 
shinyApp(ui=ui, server=server) 

Methods

Basically, the steps of coding include 1) create a template, 2) add elements as arguments to fluidPage(), 3) create reactive inputs with Input(), and 4) display reactive results with an Output() function. You need to tell the server how to assemble inputs into outputs, and then use input values with input$name. If you want to share your app online, you have to save it in the working directory first and then share it through a free server from RStudio (http://www.shinyapps.io/). For practicing, I changed some codes to show how sin(x) change with input number from 1 to 10. You may check the the first Shiny App (https://zhangyang.shinyapps.io/APP1) I made for fun.

The codes shown here:

    setwd('/Users/yang/Desktop/R/APP1')
    library(shiny)
    
    ui <- fluidPage(
      titlePanel("Hello Laogo!"),
      sliderInput(inputId = "num",
                  label = "Choose a number from 1:10",
                  value = 5, min = 1, max = 10),
      plotOutput("lines")
    )
    
    server <- function(input, output) {
      output$lines <- renderPlot({
        curve(sin,-input$num*pi, input$num*pi, xname="T")
      })
    }
    
    shinyApp(ui = ui, server = server)