编织后不打开RStudio内部浏览器

时间:2023-01-17 06:04:04

I'm working on a presentation in RStudio using rmarkdown and revealjs template. Since it's a work in progress, I often knit the .Rmd file to see the changes.

我正在使用rmarkdown和aljs模板在RStudio中进行演示。由于这是一项正在进行的工作,我经常编织. rmd文件以查看更改。

The problem is, each time I press "Knit" button (or use a hotkey), an internal browser window pops up. I don't need it, really, because 1) it displays the presentation incorrectly and 2) I already have the .html file open in my system browser and I simply refresh the page.

问题是,每当我按下“针织”按钮(或使用热键)时,会弹出一个内部浏览器窗口。我不需要它,真的,因为1)它不正确地显示表示,2)我已经在我的系统浏览器中打开了。html文件,我只是刷新页面。

Is there any way to suppress the default RStudio behaviour?

有什么方法可以抑制默认的RStudio行为吗?

Ideally, I'd love to be able to knit and see the result in the system browser (with focus on it) in as few keypresses as possible. Right now, my solution is to source(render.R), which contains a call like

理想情况下,我希望能够在尽可能少的按键中编织并查看系统浏览器(重点关注它)的结果。现在,我的解决方案是使用source(render.R),它包含类似的调用

library(rmarkdown)
library(revealjs)
render("main.Rmd", 
       revealjs_presentation(theme="black", highlight="zenburn"), 
       encoding = "UTF-8")

Better than nothing, but still a bit tedious (set focus from editing to console, source, refresh page -- 3 actions). Any suggestions?

总比什么都没有好,但还是有点乏味(从编辑到控制台、源、刷新页面——3个动作)。有什么建议吗?

For an MWE, open [New File] -- [R Markdown...] and hit "Knit HTML" or Ctrl+Shift+K.

对于MWE,打开[新文件]- [R Markdown…]然后点击“编织HTML”或Ctrl+Shift+K。

2 个解决方案

#1


6  

RStudio keeps moving this feature around. Johnathan's answer was good for the prior version of RStudio that I was using. You could find it starting with Tools > Global Options and then if you are on 0.99.x, here:

RStudio不断地移动这个特性。乔纳森的回答对我之前使用的RStudio很有帮助。你可以从>的全球选项开始,然后如果你是0。99。x在这里:

编织后不打开RStudio内部浏览器

I'm currently on 1.0.44 and now it's here:

我现在在1。0.44,现在在这里:

编织后不打开RStudio内部浏览器

In all fairness to RStudio, I think creating a new R Markdown option section and putting it here makes good sense.

公平地说,我认为创建一个新的R Markdown选项节并将其放在这里是很有意义的。

#2


2  

To add a litte bit to the answer of Michael (on how to disable the internal window):

在Michael(关于如何禁用内部窗口)的回答中添加一个litte位:

I am using only the following script by sourcing it to render the file and open the resulting html file in the browser in one step:

我只使用了以下脚本,将其用于呈现文件并在浏览器中按一步打开生成的html文件:

library(rmarkdown)
library(revealjs)

file.name <- "introduction"
path.to.file <- "vignettes/"

rmarkdown::render(file.path(path.to.file, paste0(file.name, ".Rmd")),
       revealjs_presentation(theme="default", highlight="default"),
       encoding = "UTF-8")

browseURL( file.path(path.to.file, paste0(file.name, ".html")))

Note: This script does also work within a package project of RStudio.

注意:这个脚本也可以在RStudio的包项目中使用。

#1


6  

RStudio keeps moving this feature around. Johnathan's answer was good for the prior version of RStudio that I was using. You could find it starting with Tools > Global Options and then if you are on 0.99.x, here:

RStudio不断地移动这个特性。乔纳森的回答对我之前使用的RStudio很有帮助。你可以从>的全球选项开始,然后如果你是0。99。x在这里:

编织后不打开RStudio内部浏览器

I'm currently on 1.0.44 and now it's here:

我现在在1。0.44,现在在这里:

编织后不打开RStudio内部浏览器

In all fairness to RStudio, I think creating a new R Markdown option section and putting it here makes good sense.

公平地说,我认为创建一个新的R Markdown选项节并将其放在这里是很有意义的。

#2


2  

To add a litte bit to the answer of Michael (on how to disable the internal window):

在Michael(关于如何禁用内部窗口)的回答中添加一个litte位:

I am using only the following script by sourcing it to render the file and open the resulting html file in the browser in one step:

我只使用了以下脚本,将其用于呈现文件并在浏览器中按一步打开生成的html文件:

library(rmarkdown)
library(revealjs)

file.name <- "introduction"
path.to.file <- "vignettes/"

rmarkdown::render(file.path(path.to.file, paste0(file.name, ".Rmd")),
       revealjs_presentation(theme="default", highlight="default"),
       encoding = "UTF-8")

browseURL( file.path(path.to.file, paste0(file.name, ".html")))

Note: This script does also work within a package project of RStudio.

注意:这个脚本也可以在RStudio的包项目中使用。