Download_this 按钮和 RMarkdown 中的绘图
我有一个带有各种绘图的 Rmarkdown 文档。我希望用户能够下载文档中每个图表背后的数据集。 我尝试使用“download_this”包,它正在工作,但它会影响我的图表并移动图例和轴名称。
我该怎么做才能避免这种情况?
这是我的代码:
---
title: "Fiche"
output:
rmdformats::material:
highlight: kate
self_contained: no
---
```{r setup, include=FALSE}
## Global options
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
library(ggplot2)
library(DT)
library(rmarkdown)
library(plotly)
library(scales)
library(plyr)
library(Cairo)
library(ggiraph)
library(shiny)
library(knitr)
library(extrafont)
library(openxlsx)
library(downloadthis)
library(kableExtra)
library(rmdformats)
# Evolution
```{r, echo = FALSE}
test2 <- read.xlsx("C:/Users/cccc/Documents/Classeur1.xlsx",sheet="Feuil2",colNames = TRUE)
q <- plot_ly(
data = test2,
x = ~Annee,
y = ~Effectifs,
color = ~Secteur,
type = "scatter",
mode = "lines+markers",
marker =list(hoverformat = ',.0f')) %>%
layout(title = list(text ='Evolution des effectifs par secteur (indice 100)'),
xaxis = list(title = list(text ='Année scolaire')),
yaxis = list(title = list(text = 'Effectifs indice 100')),
legend = list(title=list(text='Secteur')),
hovermode = ("x unified"))
ggplotly(q) %>% config(displaylogo = FALSE,
modeBarButtonsToRemove = c(
'sendDataToCloud',
'zoom3d',
'zoom2d',
'toggleSpikelines',
'autoScale2d',
'resetScale2d',
'select2d',
'lasso2d',
'hoverClosestCartesian',
'hoverCompareCartesian',
'pan2d'
)
)
test2 %>%
download_this(
output_name = "test2 data set",
output_extension = ".csv",
button_label = "Download data",
button_type = "warning",
has_icon = TRUE,
icon = "fa fa-save"
)
这是有关“download_this”的信息:https://fmmattioni.github.io/downloadthis/index.html
感谢您的帮助!
I have a Rmarkdown document with various plotly graph. I want the users to be able to download the dataset behind every graph in the document.
I have tried using the "download_this" package and it is working but it impacts my graph and moves the legend and axis names.
What can I do to avoid this ?
Here's my code :
---
title: "Fiche"
output:
rmdformats::material:
highlight: kate
self_contained: no
---
```{r setup, include=FALSE}
## Global options
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
library(ggplot2)
library(DT)
library(rmarkdown)
library(plotly)
library(scales)
library(plyr)
library(Cairo)
library(ggiraph)
library(shiny)
library(knitr)
library(extrafont)
library(openxlsx)
library(downloadthis)
library(kableExtra)
library(rmdformats)
# Evolution
```{r, echo = FALSE}
test2 <- read.xlsx("C:/Users/cccc/Documents/Classeur1.xlsx",sheet="Feuil2",colNames = TRUE)
q <- plot_ly(
data = test2,
x = ~Annee,
y = ~Effectifs,
color = ~Secteur,
type = "scatter",
mode = "lines+markers",
marker =list(hoverformat = ',.0f')) %>%
layout(title = list(text ='Evolution des effectifs par secteur (indice 100)'),
xaxis = list(title = list(text ='Année scolaire')),
yaxis = list(title = list(text = 'Effectifs indice 100')),
legend = list(title=list(text='Secteur')),
hovermode = ("x unified"))
ggplotly(q) %>% config(displaylogo = FALSE,
modeBarButtonsToRemove = c(
'sendDataToCloud',
'zoom3d',
'zoom2d',
'toggleSpikelines',
'autoScale2d',
'resetScale2d',
'select2d',
'lasso2d',
'hoverClosestCartesian',
'hoverCompareCartesian',
'pan2d'
)
)
test2 %>%
download_this(
output_name = "test2 data set",
output_extension = ".csv",
button_label = "Download data",
button_type = "warning",
has_icon = TRUE,
icon = "fa fa-save"
)
Here's the information on "download_this" : https://fmmattioni.github.io/downloadthis/index.html
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 download_this 函数中,有一个名为“self_contained”的参数,其默认值为 FALSE。将参数指定为 TRUE,它应该可以解决问题:
In the download_this function, there's an argument called "self_contained" which its default value is FALSE. Specify the argument as TRUE and it should fix the issue: