Download_this 按钮和 RMarkdown 中的绘图

发布于 2025-01-10 22:39:27 字数 2116 浏览 0 评论 0原文

我有一个带有各种绘图的 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 ?

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剪不断理还乱 2025-01-17 22:39:27

在 download_this 函数中,有一个名为“self_contained”的参数,其默认值为 FALSE。将参数指定为 TRUE,它应该可以解决问题:

test2 %>%
  download_this(
    output_name = "test2 data set",
    ...,
    self_contained = 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:

test2 %>%
  download_this(
    output_name = "test2 data set",
    ...,
    self_contained = TRUE
  )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文