{"id":1699,"date":"2024-08-29T15:33:38","date_gmt":"2024-08-29T13:33:38","guid":{"rendered":"https:\/\/inseri.swiss\/?p=1699"},"modified":"2025-11-26T15:33:38","modified_gmt":"2025-11-26T15:33:38","slug":"r-code-block-using-webr","status":"publish","type":"post","link":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/2024\/08\/r-code-block-using-webr\/","title":{"rendered":"R Code Block using WebR"},"content":{"rendered":"\n<p>The&nbsp;<strong>R Code<\/strong>&nbsp;block relies on the&nbsp;<a href=\"https:\/\/webr.r-wasm.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">WebR<\/a>&nbsp;project. It allows us to run R Code directly in the browser.<\/p>\n\n\n\n<p>Next, we use two Text Editor (JSON content) blocks to allow the visitors to provide two variables.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-inseri-core-text-editor\" data-attributes=\"{&quot;blockId&quot;:&quot;H5J2W7v6GU4aSy1KRtTXf&quot;,&quot;content&quot;:&quot;1&quot;,&quot;contentType&quot;:&quot;application\/json&quot;,&quot;editable&quot;:true,&quot;height&quot;:60,&quot;isVisible&quot;:true,&quot;label&quot;:&quot;Variable a:&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;textEditor-r-a&quot;}}\">is loading &#8230;<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-inseri-core-text-editor\" data-attributes=\"{&quot;blockId&quot;:&quot;N38McwVhSC8H97OGhLxdy&quot;,&quot;content&quot;:&quot;2&quot;,&quot;contentType&quot;:&quot;application\/json&quot;,&quot;editable&quot;:true,&quot;height&quot;:60,&quot;isVisible&quot;:true,&quot;label&quot;:&quot;Variable b:&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;textEditor-r-b&quot;}}\">is loading &#8230;<\/div>\n<\/div>\n<\/div>\n\n\n\n<p>We are using the &#8220;+&#8221; operator between the content of the two blocks above.<br>The R block can run on demand (press <strong>Run<\/strong>), automatically, and one can even hide it.<br>Moreover, we can make it editable, so the users can change it.<\/p>\n\n\n\n<div class=\"wp-block-inseri-core-r-code\" data-attributes=\"{&quot;autoTrigger&quot;:false,&quot;blockId&quot;:&quot;9zrXQvLJJ3N0bXxgqQVYR&quot;,&quot;content&quot;:&quot;res%20%3D%20a%2Bb&quot;,&quot;editable&quot;:true,&quot;height&quot;:60,&quot;inputCode&quot;:&quot;&quot;,&quot;inputs&quot;:{&quot;a&quot;:&quot;H5J2W7v6GU4aSy1KRtTXf\/content&quot;,&quot;b&quot;:&quot;N38McwVhSC8H97OGhLxdy\/content&quot;},&quot;isVisible&quot;:true,&quot;label&quot;:&quot;Feel free to edit the R code&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;r-res&quot;},&quot;mode&quot;:&quot;editor&quot;,&quot;outputs&quot;:[[&quot;res&quot;,&quot;application\/json&quot;]]}\">is loading &#8230;<\/div>\n\n\n\n<p>And below we display the result in a Text Viewer block.<\/p>\n\n\n\n<div class=\"wp-block-inseri-core-text-viewer\" data-attributes=\"{&quot;blockId&quot;:&quot;uiqCFnoPovk31MNBE12QQ&quot;,&quot;content&quot;:&quot;&quot;,&quot;height&quot;:60,&quot;inputKey&quot;:&quot;9zrXQvLJJ3N0bXxgqQVYR\/res&quot;,&quot;label&quot;:&quot;The value of res:&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;textViewer-r-res&quot;}}\">is loading &#8230;<\/div>\n\n\n\n<p>Feel free to experiment, e.g. change the value or the operator.<\/p>\n\n\n\n<p>For more details please see the corresponding <a href=\"https:\/\/inseri-swiss.github.io\/inseri-core-wp\/blocks\/rCode\/\" target=\"_blank\" rel=\"noreferrer noopener\">documentation<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:60%\"><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-inseri-core-export alignright\" data-attributes=\"{&quot;align&quot;:&quot;right&quot;,&quot;blockId&quot;:&quot;vaxQQCzmrnvQCf4meQgfk&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;export&quot;},&quot;postId&quot;:1699}\">is loading &#8230;<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-inseri-core-share alignright\" data-attributes=\"{&quot;align&quot;:&quot;right&quot;,&quot;blockId&quot;:&quot;KTETwIissQyi0jL3ZpuwV&quot;,&quot;copiedText&quot;:&quot;Copied&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;share&quot;},&quot;showIcon&quot;:true,&quot;text&quot;:&quot;Share&quot;}\">is loading &#8230;<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The&nbsp;R Code&nbsp;block relies on the&nbsp;WebR&nbsp;project. It allows us to run R Code directly in the browser. Next, we use two Text Editor (JSON content) blocks to allow the visitors to provide two variables. We are using the &#8220;+&#8221; operator between the content of the two blocks above.The R block can run on demand (press Run), [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[40,49,50,52,53],"class_list":["post-1699","post","type-post","status-publish","format-standard","hentry","category-inseri-core-block","tag-export","tag-r-code","tag-share","tag-text-editor","tag-text-viewer"],"_links":{"self":[{"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts\/1699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/comments?post=1699"}],"version-history":[{"count":1,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts\/1699\/revisions"}],"predecessor-version":[{"id":2133,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts\/1699\/revisions\/2133"}],"wp:attachment":[{"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/media?parent=1699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/categories?post=1699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/tags?post=1699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}