Each shiny
app contains two parts: A user interface definition (UI
) and a server script (server
). This example shows how you can print "Hello world" from UI or from server.
UI.R
In the UI you can place some view objects (div, inputs, buttons, etc).
library(shiny)
# Define UI for application print "Hello world"
shinyUI(
# Create bootstrap page
fluidPage(
# Paragraph "Hello world"
p("Hello world"),
# Create button to print "Hello world" from server
actionButton(inputId = "Print_Hello", label = "Print_Hello World"),
# Create position for server side text
textOutput("Server_Hello")
)
)
Server.R
In the server script you can define methods which manipulate data or listen to actions.
# Define server logic required to print "Hello World" when button is clicked
shinyServer(function(input, output) {
# Create action when actionButton is clicked
observeEvent(input$Print_Hello,{
# Change text of Server_Hello
output$Server_Hello = renderText("Hello world from server side")
})
})
How to run?
You can run your app in several ways:
runApp('your dir path')
shinyApp(ui,server)
to run your appResult
In this example you will see some text and a button:
And after button click the server responds: