Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statistical tests not displayed in HTML output with pfootnote = TRUE in Shiny #371

Open
PietropaoliLab opened this issue Aug 11, 2024 · 1 comment

Comments

@PietropaoliLab
Copy link

Hello,
I’m experiencing an issue with including statistical tests in the HTML output of a Shiny app using the arsenal package. Despite setting pfootnote = TRUE in the summary(tableby(...)) function, the statistical tests do not appear in the generated HTML output.

Here is the code I am using:

library(shiny)
library(arsenal)
data(mockstudy)

shinyApp(
  ui = fluidPage(tableOutput("table")),
  server = function(input, output) {
    output$table <- renderTable({
      as.data.frame(summary(tableby(sex ~ age, data = mockstudy), text = "html", pfootnote = TRUE))
    }, sanitize.text.function = function(x) x)
  }
)

The HTML output generated by this code is as follows:

<table>
 <thead>
  <tr>
   <th style="text-align:left;">  </th>
   <th style="text-align:center;"> Female (N=6) </th>
   <th style="text-align:center;"> Male (N=13) </th>
   <th style="text-align:center;"> Total (N=19) </th>
   <th style="text-align:right;"> p value </th>
  </tr>
 </thead>
<tbody>
  <tr>
   <td style="text-align:left;"> <strong>DM</strong> </td>
   <td style="text-align:center;">  </td>
   <td style="text-align:center;">  </td>
   <td style="text-align:center;">  </td>
   <td style="text-align:right;"> 0.405<sup>1</sup> </td>
  </tr>
  <tr>
   <td style="text-align:left;"> &nbsp;&nbsp;&nbsp;No </td>
   <td style="text-align:center;"> 4 (66.7%) </td>
   <td style="text-align:center;"> 6 (46.2%) </td>
   <td style="text-align:center;"> 10 (52.6%) </td>
   <td style="text-align:right;">  </td>
  </tr>
  <tr>
   <td style="text-align:left;"> &nbsp;&nbsp;&nbsp;Yes </td>
   <td style="text-align:center;"> 2 (33.3%) </td>
   <td style="text-align:center;"> 7 (53.8%) </td>
   <td style="text-align:center;"> 9 (47.4%) </td>
   <td style="text-align:right;">  </td>
  </tr>
  <tr>
   <td style="text-align:left;"> <strong>age</strong> </td>
   <td style="text-align:center;">  </td>
   <td style="text-align:center;">  </td>
   <td style="text-align:center;">  </td>
   <td style="text-align:right;"> 0.216<sup>2</sup> </td>
  </tr>
  <tr>
   <td style="text-align:left;"> &nbsp;&nbsp;&nbsp;Mean (SD) </td>
   <td style="text-align:center;"> 70.500 (8.503) </td>
   <td style="text-align:center;"> 64.308 (10.250) </td>
   <td style="text-align:center;"> 66.263 (9.943) </td>
   <td style="text-align:right;">  </td>
  </tr>
  <tr>
   <td style="text-align:left;"> &nbsp;&nbsp;&nbsp;Range </td>
   <td style="text-align:center;"> 59.000 - 83.000 </td>
   <td style="text-align:center;"> 45.000 - 86.000 </td>
   <td style="text-align:center;"> 45.000 - 86.000 </td>
   <td style="text-align:right;">  </td>
  </tr>
</tbody>
</table>
1. Pearson's Chi-squared test
2. Linear Model ANOVA

As shown, the statistical tests (footnotes) are included at the bottom, but they do not appear as expected in the rendered HTML output. It seems that the pfootnote argument is not being applied correctly.

Could you please assist in diagnosing this issue or suggest a workaround to ensure the statistical tests are displayed properly in the HTML output?

Thank you!

@PietropaoliLab
Copy link
Author

I solved this issue with HTML(capture.output(x)).
Here the code chunk:

library(shiny)
library(arsenal)
data(mockstudy)

shinyApp(
  ui = fluidPage(tableOutput("table")),
  server = function(input, output) {
    output$table <- renderTable({
      
      # Use capture.output and HTML to solve the issue
      HTML(capture.output(summary(tableby(sex ~ age + race + bmi, data = mockstudy), text = "html", pfootnote = TRUE)))
      
    }, sanitize.text.function = function(x) x)
  }
)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant