20.3 Converting an existing app

  1. Call usethis::create_package("pick-a-path"). This will create the package directory and skeleton.
  2. Remove any library() or require() calls, in favor of usethis::use_package("name").
  3. If your app uses modules, place related ones in individual .R files with usethis::use_r("module-category").
  4. Wrap core app inside a function and place within a .R file, e.g:
greetingApp <- function() {
# define a user-interface with two elements: a text input with an ID, 
# label, and initial value; define a textOutput that 
# returns the input + greeting
ui <- fluidPage(
  textInput(inputId = "nameInput", 
            label = "What is your name?", 
            value = "World"),
  textOutput("name")
)

# define the server side logic to manipulate the inputs
server <- function(input, output, session) {
  # define the output that concatenates the strings 
  # "Hello, " + user input + "."
  output$name <- renderText({paste0("Hello, ", input$nameInput, ".")})
}

# run the application
shinyApp(ui, server)
}
  1. Call devtools::load_all() and your function – greetingApp() to say hello to your package!