Skip to contents

Output and render functions for using km() within Shiny applications and interactive R Markdown / Quarto documents.

Usage

kmOutput(output_id, width = "100%", height = "520px")

renderKm(expr, env = parent.frame(), quoted = FALSE)

Arguments

output_id

Output variable to read from.

width, height

Element size, passed to htmlwidgets::shinyWidgetOutput().

expr

An expression that generates a km() widget.

env

The environment in which to evaluate expr.

quoted

Is expr already quoted? Defaults to FALSE.

Value

kmOutput() returns a Shiny output UI element; renderKm() returns a Shiny render function.

Examples

if (interactive() && requireNamespace("shiny", quietly = TRUE)) {
  ui <- shiny::fluidPage(kmOutput("surv"))
  server <- function(input, output) {
    output$surv <- renderKm({
      km(data.frame(
        time = c(0, 5, 12, 0, 7, 15),
        surv = c(1, 0.9, 0.7, 1, 0.8, 0.5),
        group = rep(c("treated", "control"), each = 3)
      ))
    })
  }
  shiny::shinyApp(ui, server)
}