Autre exemple avec un graphique

Autre exemple

if (!require("pacman")) install.packages("pacman")
pacman::p_load(bslib, shiny, shinylive, shinythemes, shinydashboard)

ui <- page_sidebar(

  title = "Importance de la taille d'échantillon",

  sidebar = sidebar(

    radioButtons(
      "dist",
      "Loi de distribution:",
      c(
        "Normale" = "norm",
        "Uniforme" = "unif",
        "Log-normale" = "lnorm",
        "Exponentielle" = "exp"
      )
    ),
    
    br(),

    numericInput(
      "n",
      "Nombre d'observations:",
      value = 300,
      min = 1,
      max = 10000
    )
  ),

  navset_card_underline(

    nav_panel("Plot", plotOutput("plot")),

    nav_panel("Summary", verbatimTextOutput("summary")),

    nav_panel("Table", tableOutput("table")), 
    
    nav_panel("Télécharger les données", downloadButton("Data","Télécharger les données"))
  )
)

server <- function(input, output) {

  d <- reactive({
    dist <- switch(
      input$dist,
      norm = rnorm,
      unif = runif,
      lnorm = rlnorm,
      exp = rexp,
      rnorm
    )

    dist(input$n)
  })

  output$plot <- renderPlot({
    dist <- input$dist
    n <- input$n

    hist(
      d(),
      main = paste("r", dist, "(", n, ")", sep = ""),
      col = "aquamarine",
      border = "white"
    )
  })

  output$summary <- renderPrint({
    summary(d())
  })

  output$table <- renderTable({
    d()
  })

 output$Data <- downloadHandler(
  filename = function() {
    "Data.csv"
  },
  content = function(file) {
    write.csv2(d(), file, row.names = FALSE)
  }
)

}

shinyApp(ui, server) 

Retrouvez cet exemple en ligne ici.