SISBID 2025
https://github.com/dicook/SISBID
File
menu, New file
, Shiny web app
to start a new appSingle file
, which will put both server and ui functions in the same file, app.R
Shiny has many different input options, see the widget gallery:
actionButton()
- creates a clickable buttonselectInput()
create a select listcheckboxInput()
and checkboxGroupInput()
dateInput()
- calendar to select a datedateRangeInput()
- select a range of datesfileInput()
- upload a filenumericInput()
- input a numeric valueradioButtons()
- select one or more itemssliderInput()
- slide along a range of valuestextInput()
- input a stringAdd a list of your favorite countries to the sidebar panel:
05:00
ui
function we need to create a placeholder to reserve space for the outputserver
function, we need to create the output.ui
components are usually xxxOutput (outputID)
Output can be in form of tables, plots, text, …
server
components are renderXXX
, where xxx
is a table, plot, text, etc.
Shiny also has a variety of different output options:
renderDataTable()
- outputs an interactive, sortable data tablehtmlOutput()
- output html elementsrenderPlot()
- output an R plotrenderPrint()
- output text from print() in RrenderTable()
- output an HTML tablerenderText()
- output text from RrenderUI()
- output a custom part of the user interfacerenderImage()
- print an image to the pagelibrary(shiny)
library(ggplot2)
library(dplyr)
sidebar <- sidebarPanel(
width = 3,
selectInput(
"country", "Pick your favorite country:",
choices = c("Australia", "Brazil", "China")
)
)
main_col <- column( #<<
width = 9, #<<
plotOutput("scatter") #<<
) #<<
ui <- fluidPage(
title = "App Title", sidebar, main_col
)
server <- function(input, output, session) {
output$scatter <- renderPlot({ #<<
mtcars %>% ggplot(aes(x = disp, y = mpg)) + #<<
geom_point() + #<<
ggtitle(input$country) #<<
}) #<<
}
shinyApp(ui, server)
unique(tb$country)
for defining the choices07:00
rsconnect
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.