我正在试图找出如何使用downloadButton来保存有光泽的情节.包中的示例演示了downloadButton/downloadHandler以保存.csv.我将基于此制作一个可重现的示例.
对于 ui.R
shinyUI(pageWithSidebar(
headerPanel('Downloading Data'),
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
downloadButton('downloadData', 'Download Data'),
downloadButton('downloadPlot', 'Download Plot')
),
mainPanel(
plotOutput('plot')
)
))
Run Code Online (Sandbox Code Playgroud)
对于 server.R
library(ggplot2)
shinyServer(function(input, output) {
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
plotInput <- reactive({
df <- datasetInput()
p <-ggplot(df, aes_string(x=names(df)[1], y=names(df)[2])) +
geom_point()
})
output$plot <- renderPlot({
print(plotInput())
})
output$downloadData <- downloadHandler(
filename = function() { paste(input$dataset, '.csv', sep='') },
content = function(file) { …Run Code Online (Sandbox Code Playgroud) 默认情况下不适合幻灯片,甚至不通过任何其他方式打印.
这是.Rmd:编辑:似乎你必须在每个块中使用plot().第二个图现在打印.
# Plot should show at high resolution
```{r echo=FALSE, comment = ""}
# load some data
require(plyr)
rbi <- ddply(baseball, .(year), summarise,
mean_rbi = mean(rbi, na.rm = TRUE))
```
```{r}
# plot
plot(mean_rbi ~ year, type = "l", data = rbi)
```
# Second attempt
```{r, fig.width = 2, fig.height = 2}
plot(mean_rbi ~ year, type = "l", data = rbi)
```
# Third attempt
```{r, out.width = 2, out.height = 2}
plot(mean_rbi ~ year, type = …Run Code Online (Sandbox Code Playgroud) 我正在使用R 3.1和RStudio 0.99运行矩阵.
我有我的R脚本和cmd +输入它没有问题.
我为报告创建了一个Rmd,但是我有这个错误
Error in lazyLoadDBinsertVariable(vars[i], from, datafile, ascii, compress, :
long vectors not supported yet: ../../../../R-3.3.1/src/main/connections.c:5600
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> lazyLoadDBinsertVariable
Execution halted
Run Code Online (Sandbox Code Playgroud)
有没有办法绕过这个错误?
但不同之处在于,这仅在尝试创建Rmd时发生,而不是在任何其他情况下
我正在尝试创建一个闪亮的应用程序,允许您根据用户定义的子分析下载格式良好的PDF报告.我发现这个要点包含一个最小的例子,它运作得很好.但是,当我尝试添加一个基于Rstudio画廊的"每加仑英里数"示例的情节时,我在尝试调整代码时遇到了一些错误.
这是我的server.R代码:
library(knitr)
library(datasets)
library(ggplot2)
mpgData <- mtcars
mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual"))
shinyServer(function(input, output) {
formulaText <- reactive({
paste("mpg ~", input$variable)
})
# Return the formula text for printing as a caption
output$caption <- renderText({
formulaText()
})
# Generate a plot of the requested variable against mpg and only
# include outliers if requested
output$mpgPlot <- renderPlot({
boxplot(as.formula(formulaText()),
data = mpgData,
outline = input$outliers)
})
myPlot1 <- reactive({
p <- print(ggplot(mpgData, …Run Code Online (Sandbox Code Playgroud) 我在RStudio中使用R Markdown和编织HTML选项来创建HTML输出.但是,纯文本块的输出中使用的字体相当小,我想将其更改为不同的字体并增加字体大小.有人可以举例说明如何设置输出字体 - 在html中没有很多知识的情况下可行吗?
到目前为止,我尝试了我的降价文档的顶部,但这不起作用.
---
fontsize: 24pt
---
Run Code Online (Sandbox Code Playgroud) 我观察到了一个traceback()我不理解的交互式和非交互式R会话之间的不同.对于下面的代码,它会产生错误,但在交互式R会话中,我可以看到回溯信息,而如果我将代码保存到test.R并通过Rscript test.R或调用它R -f test.R,我将无法再看到回溯:
f = function() {
on.exit(traceback())
1 + 'a'
}
f()
Run Code Online (Sandbox Code Playgroud)
在交互式R会话中:
> f = function() {
+ on.exit(traceback())
+ 1 + 'a'
+ }
> f()
Error in 1 + "a" : non-numeric argument to binary operator
1: f()
Run Code Online (Sandbox Code Playgroud)
非交互式执行:
$ Rscript test.R
Error in 1 + "a" : non-numeric argument to binary operator
Calls: f
No traceback available
Execution halted
Run Code Online (Sandbox Code Playgroud)
我没有看到解释?traceback,我想知道是否有一种方法可以为非交互式R会话启用回溯.谢谢!
在创建html文档时,如何将计算机中的并排png文件插入rstudio?
以下效果很好(情节)
```{r, echo=FALSE,fig.width=4, fig.show='hold'}
plot(cars)
plot(rnorm(100))
```
Run Code Online (Sandbox Code Playgroud)
但对于路径中的图像,仅显示最后一个图像
```{r fig.width=3, fig.show='hold'}
library(png)
img <- readPNG("C:/path to my picture/picture.png")
grid.raster(img)
img2 <- readPNG("C:/path to my picture/picture2.png")
grid.raster(img2)
```
Run Code Online (Sandbox Code Playgroud) 我正在尝试用书籍来写我的博士论文,主要是使用pdf输出.我在文档末尾很容易添加了一个参考书目,但在每一章的末尾都有一个参考书目.我已经尝试用允许这样的LaTeX软件包来调整.tex输出,但是这会与bookownown默认值进行斗争.有没有办法调整.yaml选项来启用它?
如何创建一个简短的标题kable?
library(dplyr)
library(knitr)
library(kableExtra)
df <- data.frame( X = sample(letters, 10), y = runif(10), z = sample(10:20, 10))
kable(df,
booktabs = TRUE,
caption = "This caption is way too long and doesnt look good when formatted in the Table of Contents. What you really need here is a much shorter caption so that your eyes dont go crazy trying to figure out what information the author is trying to convey. Often there is too much information in the …Run Code Online (Sandbox Code Playgroud) 我正在尝试在bash中实现REPL(read-eval-print循环).如果这样的事情已经存在,请忽略以下内容并用指针回答这个问题.
我们以此脚本为例(命名test.sh):
if true
then
echo a
else
echo b
fi
echo c
Run Code Online (Sandbox Code Playgroud)
我想要做的是逐行阅读这个脚本,检查我到目前为止读的是否是一个完整的bash表达式; 如果它是完整的,eval它; 否则继续阅读下一行.下面的脚本有希望地说明了我的想法(尽管如此).
x=""
while read -r line
do
x=$x$'\n'$line # concatenate by \n
# the line below is certainly a bad way to go
if eval $x 2>/dev/null; then
eval $x # code seems to be working, so eval it
x="" # empty x, and start collecting code again
else
echo 'incomplete expression'
fi
done < test.sh
Run Code Online (Sandbox Code Playgroud)
对于bash脚本,我想将其解析为语法上完整的表达式,计算每个表达式,捕获输出,最后标记源代码和输出(例如,使用Markdown/HTML/LaTeX/...).例如,对于脚本
echo …Run Code Online (Sandbox Code Playgroud)