Hi!
I'm having a weird problem that I can't understand. I'm having a problem getting output to the viewer pane when I run code that used to work for me a year ago. I first thought it was related to the package I'm using, modelsummary, but I don't think so anymore, even if I'm not sure.
If I have the following code in a code chunk in a Quarto document it looks just fine if I render the file and it looks fine in a reprex.
library(modelsummary)
url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv'
dat <- read.csv(url)
models <- list(
"OLS 1" = lm(Donations ~ Literacy + Clergy, data = dat),
"Poisson" = glm(Donations ~ Literacy + Commerce, family = poisson, data = dat),
"OLS 2" = lm(Crime_pers ~ Literacy + Clergy, data = dat)
)
modelsummary(models)
It also works fine if I run the code inside the code chunk in a new Quarto document without saving it, i.e. the table is shown in the viewer pane. But after I save the Quarto document on my computer and then run the code inside the code chunk, the table doesn't appear in the viewer pane, but I get a long output in the console instead (that I assume should create the table in the viewer pane). It starts like:
[1] "\n```{=html}\n\n \n<html lang="en">\n \n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n tinytable_ntonhht73pttqf47p9p7\n <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css\" rel="stylesheet">\n \n \n\n\n \n\n function styleCell_ntonhht73pttqf47p9p7(i, j, css_id) {\n var table = document.getElementById("tinytable_ntonhht73pttqf47p9p7");\n var cell = table.rows[i]?.cells[j]; // Safe navigation to avoid errors\n if (cell) {\n console.log(Styling cell at (${i}, ${j}) with class ${css_id}
);\n cell.classList.add(css_id);\n } else {\n console.warn(Cell at (${i}, ${j}) not found.
);\n }\n }\n function insertSpanRow(i, colspan, content) {\n var table = document.getElementById('tinytable_ntonhht73pttqf47p9p7');\n var newRow = table.insertRow(i);\n var newCell = newRow.insertCell(0);\n newCell.setAttribute("colspan", colspan);\n // newCell.innerText = content;\n // this may be unsafe, but innerText does not interpret
\n newCell.innerHTML = content;\n }\n function spanCell_ntonhht73pttqf47p9p7(i, j, rowspan, colspan) {\n var table = document.getElementById("tinytable_ntonhht73pttqf47p9p7");\n const targetRow = table.rows[i];\n const targetCell = targetRow.cells[j];\n for (let r = 0; r < rowspan; r++) {\n // Only start deleting cells to the right for the first row (r == 0)\n if (r === 0) {\n // Delete cells to the right of the target cell in the first row\n for (let c = colspan - 1; c > 0; c--) {\n if (table.rows[i + r].cells[j + c]) {\n table.rows[i + r].deleteCell(j + c);\n }\n }\n }\n // For rows below the first, delete starting from the target column\n if (r > 0) {\n for (let c = colspan - 1; c >= 0; c--) {\n if (table.rows[i + r] && table.rows[i + r].cells[j]) {\n table.rows[i + r].deleteCell(j);\n }\n }\n }\n }\n // Set rowspan and colspan of the target cell\n targetCell.rowSpan = rowspan;\n targetCell.colSpan = colspan;\n }\n // tinytable span after\n window.addEventListener('load', function () {\n var cellsToStyle = [\n // tinytable style arrays after\n { positions: [ { i: 16, j: 1 }, { i: 16, j: 2 }, { i: 16, j: 3 }, ], css_id: 'tinytable_css_x7q5p6viuxx4t8gftzfk',}, \n { positions: [ { i: 0, j: 1 }, { i: 0, j: 2 }, { i: 0, j: 3 }, ], css_id: 'tinytable_css_x15pj8iey8dqe4d47a5k',}, \n ...
and so on.
It still looks just fine when I render the file to a pdf or create a reprex. I can't understand why it behaves differently after I have saved the Quarto document. If I change the settings in R Studio, and tick the box for "Show output inline for all R Markdown documents" under Global options/R Markdown, I get the following warning message when I run the code inside the code chunk:
Registered S3 method overwritten by 'rmarkdown':
method from
print.paged_df
But the table is displayed inside the Quarto document. However, not in the viewer pane.
All packages, R, and R Studio are updated. I have the same problem on two different laptops (with the same settings).
Anyone with any suggestions about what might be the problem?
Richard
Session info:
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)
Matrix products: default
locale:
[1] LC_COLLATE=Swedish_Sweden.utf8 LC_CTYPE=Swedish_Sweden.utf8
[3] LC_MONETARY=Swedish_Sweden.utf8 LC_NUMERIC=C
[5] LC_TIME=Swedish_Sweden.utf8
time zone: Europe/Stockholm
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] modelsummary_2.2.0
loaded via a namespace (and not attached):
[1] digest_0.6.37 tables_0.9.31 backports_1.5.0 tinytable_0.6.1
[5] fastmap_1.2.0 xfun_0.49 datawizard_1.0.0 lattice_0.22-6
[9] glue_1.8.0 zoo_1.8-12 parameters_0.24.1 knitr_1.49
[13] htmltools_0.5.8.1 rmarkdown_2.29 generics_0.1.3 cli_3.6.3
[17] bayestestR_0.15.1 fansi_1.0.6 performance_0.13.0 grid_4.4.2
[21] data.table_1.16.2 compiler_4.4.2 lmtest_0.9-40 rstudioapi_0.17.1
[25] tools_4.4.2 checkmate_2.3.2 evaluate_1.0.3 rlang_1.1.4
[29] insight_1.0.1