Skip to content

Commit 404cdac

Browse files
authored
Fix renderText bug for h3 elements (#250)
* Do not remove() elements as their data is removed as well. Instead, detach() Sidebar, h1 titles, h2 -> h3, h3 -> li, chart title, headings, blockquotes, valueBox, captions. Use `append(x)` instead of `html(x)`. `html(x)` does not respect existing element information. Use `contents()` over `html()`. `contents()` will return full elements with data objects intact, `html()` returns a string. * code feedback. * fix comment * remove, do not detach old elements * chartValue is text and should be added as text * add news item
1 parent 6ad5ace commit 404cdac

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ flexdashboard 0.5.2 (unreleased)
33

44
* Support use of Font Awesome icon sets (e.g. "fab fa-r-project")
55

6+
* Fixed [#245](https://github.com/rstudio/flexdashboard/issues/245): Shiny (1.4.0+) outputs not rendering in modified flexdashboard html. ([#250](https://github.com/rstudio/flexdashboard/pull/250))
7+
68

79
flexdashboard 0.5.1
810
===========

inst/rmarkdown/templates/flex_dashboard/resources/flexdashboard.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ var FlexDashboard = (function () {
7272
globalSidebar.addClass('level3');
7373
var h1 = globalSidebar.children('h1');
7474
var h3 = $('<h3></h3>');
75-
h3.html(h1.html());
75+
h3.append(h1.contents());
7676
h3.insertBefore(h1);
77-
h1.remove();
77+
h1.detach();
7878

7979
// move it into the first page
8080
var page = dashboardContainer.find('.section.level1').first();
@@ -261,10 +261,10 @@ var FlexDashboard = (function () {
261261
if (active)
262262
wrapper.addClass('active');
263263

264-
// get a reference to the h1, discover it's id and title, then remove it
264+
// get a reference to the h1, discover its inner contens, then detach it
265265
var h1 = wrapper.find('h1').first();
266-
var title = h1.html();
267-
h1.remove();
266+
var title = h1.contents();
267+
h1.detach();
268268

269269
// create a navbar item
270270
var li = $('<li></li>');
@@ -402,9 +402,9 @@ var FlexDashboard = (function () {
402402
sidebar.wrapInner('<div class="section level3"></div>');
403403
var h2 = sidebar.find('h2');
404404
var h3 = $('<h3></h3>');
405-
h3.html(h2.html());
405+
h3.append(h2.contents());
406406
h3.insertBefore(h2);
407-
h2.remove();
407+
h2.detatch();
408408

409409
// wipeout h2 elements then enclose them in a single h2
410410
var level2 = page.find('div.section.level2');
@@ -546,8 +546,8 @@ var FlexDashboard = (function () {
546546
// extract the title from the h3
547547
var li = $('<li></li>');
548548
var h3 = frame.children('h3');
549-
li.html(h3.html());
550-
h3.remove();
549+
li.append(h3.contents());
550+
h3.detach();
551551
ul.append(li);
552552

553553
// extract commentary
@@ -943,7 +943,7 @@ var FlexDashboard = (function () {
943943

944944
// add the title
945945
var chartTitle = $('<div class="chart-title"></div>');
946-
chartTitle.html(title);
946+
chartTitle.append(title);
947947
chart.prepend(chartTitle);
948948

949949
// add the notes section
@@ -999,10 +999,11 @@ var FlexDashboard = (function () {
999999

10001000
// get the heading element within it and grab it's text
10011001
var heading = tab.find('h' + tabLevel + ':first');
1002-
var headingText = heading.html();
1002+
var headingDom = heading.contents();
10031003

10041004
// build and append the tab list item
1005-
var a = $('<a role="tab" data-toggle="tab">' + headingText + '</a>');
1005+
var a = $('<a role="tab" data-toggle="tab"></a>');
1006+
a.append(headingDom);
10061007
a.attr('href', '#' + id);
10071008
a.attr('aria-controls', id);
10081009
var li = $('<li role="presentation"></li>');
@@ -1125,8 +1126,8 @@ var FlexDashboard = (function () {
11251126
var h3 = container.children('h3').first();
11261127
var title = '';
11271128
if (!container.hasClass('no-title'))
1128-
title = h3.html();
1129-
h3.remove();
1129+
title = h3.contents();
1130+
h3.detach();
11301131
return title;
11311132
}
11321133

@@ -1137,11 +1138,11 @@ var FlexDashboard = (function () {
11371138
var caption = chartContent.children('div.image-container')
11381139
.children('p.caption');
11391140
if (blockquote.length) {
1140-
chartNotes.html(blockquote.children('p:first-child').html());
1141+
chartNotes.empty().append(blockquote.children('p:first-child').contents());
11411142
blockquote.remove();
11421143
return true;
11431144
} else if (caption.length) {
1144-
chartNotes.html(caption.html());
1145+
chartNotes.empty().append(caption.contents());
11451146
caption.remove();
11461147
return true;
11471148
} else {
@@ -1671,7 +1672,7 @@ window.FlexDashboardComponents.push({
16711672

16721673
// caption
16731674
var caption = $('<p class="caption"></p>');
1674-
caption.html(chartTitle);
1675+
caption.append(chartTitle);
16751676

16761677
// build inner div for value box and add it
16771678
var inner = $('<div class="inner"></div>');
@@ -1772,5 +1773,3 @@ window.FlexDashboardComponents.push({
17721773
);
17731774
}
17741775
});
1775-
1776-

0 commit comments

Comments
 (0)