Not able to run document object in shiny (v8 console)

I used V8 javascript engine to run js code in shiny. However, when I tried to run document object, it threw an error as below. As shown below I am trying to declare document object but it is failing

Can anyone help me resolve this

Should we declare or define document object first? I am not sure since I am new to JS

Hi @vinayprakash808,

the vignette of V8 Using NPM packages in V8 gives a very good explanation about this - in particular

However each of these programs actually implements most JavaScript functionality on top of V8. The naked V8 engine only provides pure ECMAscript, which does not include a lot of things that you might be used to. There is no I/O (network/disk) and no DOM (window).

Thus the document object is part of the the "on top stuff" - this is the reason you can see it while running shiny (since it runs in the browser where the dom and additional logic is implemented including the document object) but not using the striped down V8 engine - it simply doesn't implement the document object.

If you want to try stuff out - start shiny hit F12 and use the browsers console - there you can access the document object.

Thanks. So you mean to say, there is no way we can use document using V8 package in shiny? The reason I am trying this is, I am new to JS and wanted to learn how things work. So took this approach

I would recommend going throught https://book.javascript-for-r.com/ especially the later parts "Web Development with Shiny" . It is a comprehensive book where the author took great care of going step by step explaining the concepts and how JS and R (Shiny in particular) interact.

Knowing V8 alone will not be enough - shiny is partly build on node js so reading through the material will help you understand the concepts better.

Spoiler alert - you will learn a lot about JS in the process.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.