Learn what the heck shiny is and how you use it!
at SQLBits
Learn what the heck shiny is and how you use it!
# variable assignment a <- 1 a
## [1] 1
# functions
paste0(c("SQL","Super"),c("Bits","Heroes"))
## [1] "SQLBits" "SuperHeroes"
## ## Attaching package: 'shiny'
## The following objects are masked from 'package:DT': ## ## dataTableOutput, renderDataTable
A shiny application report consists of two functions:
shinyServer()shinyUI()One says what to execute and the other states how to present it. Do all data manipulation, chart production in shinyServer()
defaultdisplay<-list(width="100%", height="75%")
shinyApp(
ui = fluidPage(),
, server = function(input, output) {}
, options = defaultdisplay
)
You typically split into two files:
shinyServer()shinyUI()This can then be run with runApp()
You can do a single file example app.R which contains both functions but this is typically better for very short apps.
Use these just inside shinyUI() to produce a layout
## Page Types ## 1: basicPage ## 2: bootstrapPage ## 3: fillPage ## 4: fixedPage ## 5: fluidPage ## 6: navbarPage ## 7: updateNavbarPage
shinyApp(
ui = fluidPage(dateInput("datePicker", "Pick a date:",
format="dd/mm/yy"),
dateRangeInput("dateRange", "Pick dates:",
start=Sys.Date(),
end=Sys.Date() ) ),
server = function(input, output) {}
,options = defaultdisplay
)
shinyApp(
ui = fluidPage(numericInput("vals", "Insert a number:",
value=15, min=10) ),
server = function(input, output) {}
,options = defaultdisplay
)
shinyApp(
ui = fluidPage(sliderInput("vals", "Insert a number:",
min=0, max=50, value=15) ),
server = function(input, output) {}
,options = defaultdisplay
)
shinyApp(
ui = fluidPage(textInput("char", "Insert text:") ),
server = function(input, output) {}
,options = defaultdisplay
)
shinyApp(
ui = fluidPage(tags$textarea(id="charbox", rows=3,
cols=40, "Default value") ),
server = function(input, output) {}
,options = defaultdisplay
)
shinyApp(
ui = fluidPage(selectInput("multiselect", "Pick favourites:",
c("Green","Red","Blue"),
multiple=TRUE) ),
server = function(input, output) {}
,options = defaultdisplay
)
## Input controls ## 1: checkboxGroupInput ## 2: checkboxInput ## 3: dateInput ## 4: dateRangeInput ## 5: fileInput ## 6: numericInput ## 7: passwordInput ## 8: registerInputHandler ## 9: removeInputHandler ## 10: restoreInput ## 11: selectInput ## 12: selectizeInput ## 13: sliderInput ## 14: textAreaInput ## 15: textInput ## 16: updateCheckboxGroupInput ## 17: updateCheckboxInput ## 18: updateDateInput ## 19: updateDateRangeInput ## 20: updateNumericInput ## 21: updateSelectInput ## 22: updateSelectizeInput ## 23: updateSliderInput ## 24: updateTextAreaInput ## 25: updateTextInput ## Input controls
shinyApp(
ui = fluidPage(textInput("char", "Insert text:") ,
textOutput("text") ),
server = function(input, output) {
output$text <- renderText(input$char)
} ,options = defaultdisplay
)
shinyApp(
ui = fluidPage(tableOutput("basictable") ),
server = function(input, output) {
output$basictable <- renderTable(head(iris,5))
} ,options = defaultdisplay
)
shinyApp(
ui = fluidPage(dataTableOutput("datatable") ),
server = function(input, output) {
output$datatable <- renderDataTable(head(iris,5))
} ,options = defaultdisplay
)
shinyApp(
ui = fluidPage(plotOutput("chart") ),
server = function(input, output) {
output$chart <- renderPlot(pairs(iris))
} ,options = defaultdisplay
)
a <- reactive({input$a})
a
shinyApp(
ui = fluidPage(textInput("char", "Insert text:") ,
textOutput("textA"),textOutput("textB") ),
server = function(input, output) {
char<-reactive({rep(input$char,5)})
output$textA <- renderText(paste(char(),collapse="+"))
output$textB <- renderText(paste(char(),collapse="-"))
}
,options = defaultdisplay
)
shinythemesrvestshiny::runApp()shinyApps package