├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── NAMESPACE ├── R ├── app.R ├── birthstones.R └── monthFeedback.R ├── birthstones.csv ├── data └── stones.rda └── monthApp.Rproj /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^monthApp\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .Rdata 4 | .httr-oauth 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: monthApp 2 | Title: An example of a Shiny app-package 3 | Version: 0.0.0.9000 4 | Authors@R: 5 | c(person(given = "Hadley", 6 | family = "Wickham", 7 | role = c("aut", "cre"), 8 | email = "hadley@rstudio.com"), 9 | person(given = "RStudio", 10 | role = c("cph", "fnd"))) 11 | Description: What the package does (one paragraph). 12 | License: `use_mit_license()`, `use_gpl3_license()` or friends to 13 | pick a license 14 | Encoding: UTF-8 15 | LazyData: true 16 | Roxygen: list(markdown = TRUE) 17 | RoxygenNote: 7.1.1 18 | Depends: 19 | R (>= 2.10) 20 | URL: https://github.com/hadley/monthApp 21 | BugReports: https://github.com/hadley/monthApp/issues 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | -------------------------------------------------------------------------------- /R/app.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | 3 | monthApp <- function(...) { 4 | months <- c( 5 | "January", "February", "March", "April", "May", "June", 6 | "July", "August", "September", "October", "November", "December" 7 | ) 8 | 9 | ui <- navbarPage( 10 | "Sample app", 11 | tabPanel("Pick a month", 12 | selectInput("month", "What's your favourite month?", choices = months) 13 | ), 14 | tabPanel("Feedback", monthFeedbackUI("tab1")), 15 | tabPanel("Birthstone", birthstoneUI("tab2")) 16 | ) 17 | server <- function(input, output, session) { 18 | monthFeedbackServer("tab1", reactive(input$month)) 19 | birthstoneServer("tab2", reactive(input$month)) 20 | } 21 | shinyApp(ui, server, ...) 22 | } 23 | -------------------------------------------------------------------------------- /R/birthstones.R: -------------------------------------------------------------------------------- 1 | birthstoneUI <- function(id) { 2 | p( 3 | "The birthstone for ", textOutput(NS(id, "month"), inline = TRUE), 4 | " is ", textOutput(NS(id, "stone"), inline = TRUE) 5 | ) 6 | } 7 | birthstoneServer <- function(id, month) { 8 | stopifnot(is.reactive(month)) 9 | 10 | moduleServer(id, function(input, output, session) { 11 | stone <- reactive(stones$stone[stones$month == month()]) 12 | output$month <- renderText(month()) 13 | output$stone <- renderText(stone()) 14 | }) 15 | } 16 | -------------------------------------------------------------------------------- /R/monthFeedback.R: -------------------------------------------------------------------------------- 1 | monthFeedbackUI <- function(id) { 2 | textOutput(NS(id, "feedback")) 3 | } 4 | monthFeedbackServer <- function(id, month) { 5 | stopifnot(is.reactive(month)) 6 | 7 | moduleServer(id, function(input, output, session) { 8 | output$feedback <- renderText({ 9 | if (month() == "October") { 10 | "You picked a great month!" 11 | } else { 12 | "Eh, you could do better." 13 | } 14 | }) 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /birthstones.csv: -------------------------------------------------------------------------------- 1 | month,stone 2 | January,garnet 3 | February,amethyst 4 | March,aquamarine 5 | April,diamond 6 | May,emerald 7 | June,pearl 8 | July,ruby 9 | August,peridot 10 | September,sapphire 11 | October,opal 12 | November,topaz 13 | December,tanzanite 14 | -------------------------------------------------------------------------------- /data/stones.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hadley/monthApp/9899da4c89f4114a0611b415f4a329daeb753069/data/stones.rda -------------------------------------------------------------------------------- /monthApp.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: XeLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | LineEndingConversion: Posix 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace 23 | --------------------------------------------------------------------------------