gtsummary icon indicating copy to clipboard operation
gtsummary copied to clipboard

Feature request: Add vignette that shows how to use {gtsummary} with R Shiny

Open parmsam opened this issue 2 years ago • 3 comments

Do not use this form to ask a question, or ask for assistance. Instead, ask on https://stackoverflow.com/ using the gtsummary tag. Questions about a function's use will be closed without a response.

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Thanks for the package! gtsummary objects need to be converted into gt objects in order to render in R Shiny. Having this in a vignette would help first time users who want to use the package in a Shiny app.

Describe the solution you'd like A clear and concise description of what you want to happen.

Short vignette showing example Shiny app with {gtsummary}

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

Here is an example app that could be included in a vignette called gtsummary + shiny. I can submit a PR if that's okay.

library(shiny)
library(gtsummary)
library(gt)
library(datasets)
listDatasets <- c("USArrests", "VADeaths", "Seatbelts")
shinyApp(
  ui = fluidPage(
    selectInput("dataset", "Select dataset", listDatasets),
    gt::gt_output('table')
  ),
  server = function(input, output) {
    selectedData <- reactive({
      req(input$dataset)
      gtsummary::as_tibble(get(input$dataset, "package:datasets"))
    })
    gtObject <- reactive({
      req(input$dataset)
      gts_object <- gtsummary::tbl_summary(selectedData())
      gtsummary::as_gt(gts_object)
    })
    output$table <- render_gt({
      req(input$dataset)
      gtObject()
    })
  }
)

parmsam avatar Sep 02 '22 20:09 parmsam

@parmsam ! thanks for the post, and it sounds like a great suggestion and a PR would be great.

  • rather than a vignette, let's do an article (usethis::use_article()). it'll be posted to the website, but won't be shipped as a proper vignette with the package from CRAN.
  • do you plan on making a live app as the example? where would that live?

ddsjoberg avatar Sep 05 '22 18:09 ddsjoberg

Yes, that sounds good instead. I can host the simple example app on my shinyapps account, if needed. Here's the app: https://parmsam.shinyapps.io/example-gtsummary-app/

parmsam avatar Sep 05 '22 19:09 parmsam

hey @parmsam , apologies for the delay; i was caught up with work. I still need some time to think about where/how to incorporate Shiny examples. I'll get back to you!

ddsjoberg avatar Sep 23 '22 02:09 ddsjoberg