将r2d3中的JavaScript控制台输出呈现到浏览器控制台中,而不是可视化? [英] Render JavaScript console output from r2d3 into browser console instead of the visualization?

查看:112
本文介绍了将r2d3中的JavaScript控制台输出呈现到浏览器控制台中,而不是可视化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript控制台输出直接呈现到RStudio查看器可视化中,而不是javascript控制台中.参见文档.

JavaScript console output from r2d3 is rendered directly into the RStudio viewer visualization instead of the javascript console. See documentation.

这似乎也是

r2d3::r2d3(..., viewer = 'browser')

console.log()即使在浏览器中也不会输出到控制台.

I.e., the console.log() does not output to the console even in the browser.

是否存在一种干净的方法来更改此行为,以便将r2d3 D3.js中的console.log()信息发送到浏览器控制台?

Is there a clean way to change this behavior, for console.log() information in an r2d3 D3.js to be sent to the browser console?

推荐答案

R2D3覆盖包含可视化代码的影子DOM中的控制台.这就是更改控制台行为的原因-看起来不错,但不允许更仔细地检查对象或隐藏控制台.

R2D3 overwrites the console within the shadow DOM that contains the visualization code. This is why the console behavior is altered - which might look nice, but doesn't allow closer inspection of objects, or hiding of the console.

在创建可视化文件时,似乎没有任何参数可以修改此参数.留下两个选项,修改包或向可视化添加一行javascript.我将在这里与后者一起去.

There don't appear to be any parameters that can modify this when creating the visualization. This leaves two options, modify the package or add a line of javascript to the visualization. I'll go with the latter here.

文档窗口本身仍然保留默认的控制台行为,因此我们可以使用它来重新定义影子DOM控制台行为.在可视化文件的第一行中,添加:

The document window itself still retains default console behavior, so we can use it to redefine the shadow DOM console behavior. In the visualization, at the top line add:

console = d3.window(svg.node()).console;

还有其他访问窗口的方法,但这应该足够了,并且可能是最短的,它不适用于d3v3,可以使用:

console = svg.node().ownerDocument.defaultView.console;

是的,这不是理想的选择,但有点笨拙,但肯定比更改R源(在更新软件包时继续这样做)要容易得多.

Yes, it is not ideal and a bit hacky, but it is certainly easier than changing the R source (and continuing to do so when the package is updated).

这篇关于将r2d3中的JavaScript控制台输出呈现到浏览器控制台中,而不是可视化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆