Skip to content

Commit

Permalink
Don't send rich text response when there is no console output
Browse files Browse the repository at this point in the history
When generating the rich text response to display an R object, first
check that there is console output. If the object would not be
displayed at the console then do not generate a response, so that the
notebook more closely mimics what would be displayed at the console.
  • Loading branch information
abielr committed May 17, 2015
1 parent 99245db commit 7d0dddc
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions R/execution.r
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,25 @@ execute = function(request) {
} else {
handle_value <- function (obj) {
data <- namedlist()
if (getOption('jupyter.rich_display')) {
tryCatch(
for (mime in getOption('jupyter.display_mimetypes')) {
r <- mime2repr[[mime]](obj)
if (!is.null(r)) data[[mime]] <- r
},
error = handle_error
)
} else {
data[['text/plain']] <- repr_text(obj)
}
send_response('execute_result', request, 'iopub', list(
data = data,
metadata = namedlist(),
execution_count = execution_count))
data[['text/plain']] <- repr_text(obj)

# Only send a response when there is regular console output
if (nchar(data[['text/plain']]) > 0) {
if (getOption('jupyter.rich_display')) {
tryCatch(
for (mime in getOption('jupyter.display_mimetypes')) {
r <- mime2repr[[mime]](obj)
if (!is.null(r)) data[[mime]] <- r
},
error = handle_error
)
}

send_response('execute_result', request, 'iopub', list(
data = data,
metadata = namedlist(),
execution_count = execution_count))
}
}
stream = function(output, streamname) {
send_response("stream", request, 'iopub',
Expand Down

0 comments on commit 7d0dddc

Please sign in to comment.