Learn Shiny: Essential Concepts and Examples

introduction of shiny n.w
1 / 27
Embed
Share

Discover the fundamentals of Shiny, a powerful web application framework in R. Explore basic code structures, input and output functions, server logic, and more through practical examples. Start building your own interactive applications today!

  • Shiny
  • R programming
  • Web applications
  • Data visualization
  • Interactive interfaces

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Introduction of Shiny

  2. Course overview Basic code of Sniny Review important Shiny concepts Input function Output function (Server) plot

  3. Shiny app template library(shiny) # Input function # Input function ui <- fluidPange() # Output function # Output function server <- function(input, output) {} # Run application # Run application shinyApp(ui = ui, server = server) Load shiny package Create a webpage with fluidPage()-UI of ashiny app Create server portion of the app - where application logic lives Combine UI + server into a Shiny app and run it

  4. Adding Text to Shiny Add text argument to fluidPage() ui <- fluidPage( Hello there ) Result: webpage with text Hello there fluidPage() accepts arbitrary # of arguments ui <- fluidPage( Hello , there )

  5. Formatted Text h1() h2() h3() strong() em() Primary header Secondary header Third header Bold Italicized(emphasized)

  6. Main page fluidPage fluidPage ui <- fluidPage( h1( 751447 COURSE , by , strong( AJ.Boat ), ) 751447 COURSE by Aj.Boat function h1() strong() h1() strong()

  7. Sidebar Layout sidebarLayout This is the sidebar Main panel goes here ui <- fluidPage( sidebarLayout( sidebarPanel( this is the sidebar ) , mainPanel( Main panel goes here ) ) ) 2 sidebar main page

  8. Example ui <- fluidPage( "Hello there" ) server <- function(input, output) { } shinyApp(ui, server)

  9. Example ui<-fluidPage( h1( 751447 COURSE , by ,strong( AJ.Boat ), align= center , style= color:blue ) server<-function(input, output){ } shinyApp(ui,server)

  10. Server function Inputs and outputs

  11. Inputs

  12. Inputs

  13. input function ui <- fluidPage( textInput(inputId = name , label = Enter your name , value = Dean ), numericInput(inputId = sibs , label = How many siblings? , value = 4,min = 0) ) Input functions:*Input(inputId, label, ) inputId = Unique ID label = input value =

  14. Outputs Plots, table, text-anything R creates & users see Two steps: 1. Create placeholder of output (in UI) ui <- fluidPage ( Plot goes here: , plotOutput(outputId = my_plot ) )

  15. Server function Output 2. R code Output (in server) server <- function(input, output) { # Code for building outputs } 3. Server output renderTable() renderPrint() renderPlot()

  16. Example ( Use Iris data) ui <- fluidPage( numericInput( num , label= Number of row , value = 10,min = 0), tableOutput( my_table ) ) server <- function(input, output) { output$my_table <- renderTable({ head(iris, n = input$num) }) } shinyApp(ui, server)

  17. Example ( Use Iris data) ui <- fluidPage( numericInput( num , label= Number of column , value = 1,min = 1), verbatimTextOutput( my_table1 ) ) server <- function(input, output) { output$my_table1 <- renderPrint({ summary(iris[,input$num]) }) } shinyApp(ui, server)

  18. Example ( Use Iris data) ui <- fluidPage( numericInput( num , label= Number of column , value = 1,min = 1), plotOutput( my_plot ) ) server <- function(input, output) { output$my_plot <- renderPlot({ plot(iris[,input$num]) }) } shinyApp(ui, server)

  19. > x <- 5 : > y <- x+1 > x <- 10 # y ? ui <- fluidPage( numericInput( num , label= Number of x , value = 1), tableOutput( my_table2 ) ) server <- function(input, output) { output$my_ table2 <- renderTable({ y=input$num+1 y }) } shinyApp(ui, server)

  20. https://www.youtube.com/watch?v=ZKWLfW4zBYs

  21. application ( 3 ) 10 print code Present

  22. tab ui <- fluidPage( sidebarLayout( sidebarPanel( img(src="http://......", height="20%",width="20%") ), mainPanel( tabsetPanel( tabPanel("Plot", plotOutput("plot")), tabPanel("Summary", verbatimTextOutput("summary")), tabPanel("Table", tableOutput("table")) ) ) ) ) server <- function(input, output) { } shinyApp(ui, server)

  23. download save folder code shiny img(src="picture.png", height="20%",width="20%")

  24. background library(shiny) library("shinyWidgets") ui <- fluidPage( tags$h2("Change shiny app background"), setBackgroundColor(color = c("white", "red"), gradient = "linear", # linear or radial direction = "bottom") # left, right, top, bottom ) server <- function(input, output, session) { } shinyApp(ui, server)

  25. Panel ui <- fluidPage( titlePanel("Basic widgets"), fluidRow( column(3, h3("Buttons"), actionButton("action", "Action"), br(), br(), submitButton("Submit")), column(3, h3("Single checkbox"), checkboxInput("checkbox", "Choice A", value = TRUE)), column(3, checkboxGroupInput("checkGroup", h3("Checkbox group"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 1)), column(3, dateInput("date", h3("Date input"), value = "2014-01-01")) ) )

More Related Content