Skip to content

Commit

Permalink
Merge branch 'master' into usage-hiding-cells
Browse files Browse the repository at this point in the history
  • Loading branch information
bcwu authored Jul 29, 2021
2 parents 16a03bc + dda5920 commit bcaa3ca
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased
--------------------------------------------------------------------------------
* Added ability to hide all code cells when rendering Jupyter notebooks.
* Added ability to selectively hide code cells tagged with 'hide_input' when rendering Jupyter notebooks.

`rsconnect-jupyter` 1.4.1
--------------------------------------------------------------------------------
* UI now shows more error details for troubleshooting.
Expand Down
14 changes: 12 additions & 2 deletions rsconnect_jupyter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def post(self, action):
disable_tls_check = data["disable_tls_check"]
cadata = data.get("cadata", None)
extra_files = data.get("files", [])
hide_all_input = data.get("hide_all_input", False)
hide_tagged_input = data.get("hide_tagged_input", False)

model = self.contents_manager.get(path=nb_path)
if model["type"] != "notebook":
Expand All @@ -163,7 +165,9 @@ def post(self, action):

if app_mode == "static":
try:
bundle = make_notebook_html_bundle(os_path, sys.executable)
bundle = make_notebook_html_bundle(
os_path, sys.executable, hide_all_input=hide_all_input, hide_tagged_input=hide_tagged_input
)
except Exception as exc:
self.log.exception("Bundle creation failed")
raise web.HTTPError(500, u"Bundle creation failed: %s" % exc)
Expand All @@ -172,7 +176,13 @@ def post(self, action):
raise web.HTTPError(400, "environment is required for jupyter-static app_mode")

try:
bundle = make_notebook_source_bundle(os_path, Environment(**environment_dict), extra_files)
bundle = make_notebook_source_bundle(
os_path,
Environment(**environment_dict),
extra_files,
hide_all_input=hide_all_input,
hide_tagged_input=hide_tagged_input,
)
except Exception as exc:
self.log.exception("Bundle creation failed")
raise web.HTTPError(500, u"Bundle creation failed: %s" % exc)
Expand Down
39 changes: 35 additions & 4 deletions rsconnect_jupyter/static/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,17 @@ define([
' <span class="help-block"></span>',
' </div>',
' </div>',
' <div id="hide-input-wrapper">',
' <label for="hide-input-wrapper"> Hide Input</label>',
' </div>',
' <div id="hide-all-input">',
' <input type="checkbox" id="hide_all_input" name="hide_all_input" value="hide_all_input">',
' <label for="hide_all_input"> Hide all input code cells </label>',
' </div>',
' <div id="hide-tagged-input">',
' <input type="checkbox" id="hide_tagged_input" name="hide_tagged_input" value="hide_tagged_input">',
' <label for="hide_tagged_input"> Hide input code cells with the <span class="code">"hide_input"</span> tag </label>',
' </div><br>',
' <div id="add-files">',
' <label for="rsc-add-files" id="rsc-add-files-label" class="rsc-label">Additional Files</label>',
' <button id="rsc-add-files" class="btn btn-default">Select Files...</button>',
Expand Down Expand Up @@ -1345,7 +1356,8 @@ define([

function bindCheckbox(id) {
// save/restore value in server settings
var $box = $('#' + id.replace('_', '-'));
// var $box = $('#' + id.replace('_', '-'));
var $box = $('#' + id);

if (selectedEntryId) {
var updatedEntry = config.servers[selectedEntryId];
Expand All @@ -1360,8 +1372,10 @@ define([
updateCheckboxStates();
});
}
bindCheckbox('include_files');
bindCheckbox('include_subdirs');
// bindCheckbox('include_files');
// bindCheckbox('include_subdirs');
bindCheckbox('hide_all_input');
bindCheckbox('hide_tagged_input');

// setup app mode choices help icon
(function() {
Expand All @@ -1382,6 +1396,24 @@ define([
$('#rsc-publish-source > label').append(helpIcon);
})();

// setup hide input help icon
(function() {
var msg =
'Hiding input code cells results in rendering only the output of code cells on publication. <br> <a href="https://docs.rstudio.com/rsconnect-jupyter/usage/#hide-input" target="_blank">Hide Input Documentation</a>';

var helpIcon = $(
[
'<a tabindex="0" role="button" data-toggle="popover" data-trigger="focus">',
'<i class="fa fa-question-circle rsc-fa-icon"></i>'
].join('')
)
.data('content', msg)
.data('html', true)
.popover();

$('#hide-input-wrapper').append(helpIcon);
})();

var form = publishModal.find('form').on('submit', function(e) {
e.preventDefault();
publishModal.find('.form-group').removeClass('has-error');
Expand Down Expand Up @@ -1790,7 +1822,6 @@ define([
// lazily load the config when clicked since Jupyter's init
// function is racy w.r.t. loading of notebook metadata
maybeCreateConfig();

closeMenu();

// save before publishing so the server can pick up changes
Expand Down
5 changes: 5 additions & 0 deletions rsconnect_jupyter/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,8 @@ p {
font-size: .7em;
text-align: right;
}


#hide-input-wrapper {
display:flex;
}
4 changes: 3 additions & 1 deletion rsconnect_jupyter/static/rsconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ define([
environment: environment,
files: files,
disable_tls_check: entry.disableTLSCheck || false,
cadata: self.getCAData(entry.server)
cadata: self.getCAData(entry.server),
hide_all_input: entry.hide_all_input,
hide_tagged_input: entry.hide_tagged_input
};

var xhr = Utils.ajax({
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ project_urls =

[options]
install_requires =
rsconnect-python>=1.5.0
rsconnect-python>=1.5.4
notebook
nbformat
nbconvert>=5.0
nbconvert>=5.6.1
six
ipython
setup_requires =
Expand Down

0 comments on commit bcaa3ca

Please sign in to comment.