Closed zajichek closed 1 year ago
From the local repo:
library(devtools)
use_package("shiny")
The shiny
package is added under the Imports
section of DESCRIPTION
Then we can edit riskcalc_fun
(our toy function example):
riskcalc_fun <-
function()
{
# Make a UI
ui <-
shiny::fluidPage(
title = "Example App",
shiny::sidebarLayout(
shiny::sidebarPanel(
shiny::textInput(
inputId = "test_input",
label = "Add Text"
)
),
shiny::mainPanel(
shiny::textOutput(outputId = "show_text")
)
)
)
# Make the server
server <-
function(input, output) {
output$show_text <- shiny::renderText({input$test_input})
}
# Run the app
shiny::shinyApp(ui, server)
}
When we load_all()
in the development package and run riskcalc_fun()
, a shiny app is started.
Also, we can store the app in a variable, which can be used to testing, etc.
> my_app <- riskcalc_fun()
> class(my_app)
# "shiny.appobj"
Added the following to the documentation, which allowed examples to be tested w/o error in check()
:
if(interactive()) {
riskcalc_fun()
}
The main purpose of the app is to create shiny apps, so need to configure the dependency and figure out how to write a function that creates an app.