This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can code as follows:
# Part 1: include the shiny package and other necessary package, if any.
library(shiny)
library(ggplot2)
ui <- fluidPage(
# Add an Application Title
titlePanel("Addition Calculator"),
# Add a side bar with one or more inputs/outputs
sidebarPanel(width = 4,
numericInput(inputId = "x", label = "x:", value = 0),
numericInput(inputId = "y", label = "y:", value = 0),
actionButton("add", "Add")
),
# Display results on the main panel
mainPanel(
textOutput("result") # If your output were a plot, you would use plotOutput() function.
)
)
server <- function(input, output) {
output$result <- renderText({ # use "renderPlot" if result is plot
input$x + input$y # The inputs must be passed to the server via the "input" messenger
}) # The output must be passed to the browser via the "output" messenger
}
# Run the application
shinyApp(ui = ui, server = server)
##
## Listening on http://127.0.0.1:4774
You did it!