0

I have to generate a rmarkdown(html) for each row in a csv file.

Each html must contain:

  • One image
  • one plot highlighting the area
  • one plot illustrating areas distribution.

I just made this for one row.

My csv test file looks like this:

 classe  nota nome  area
      1    10   TA    10
      2     2   TB    20
      3     3   TC    30
      4     4   TD    15
      4     6   TE    15

However, I would like to generate one html for each row in my table.

Does anyone knows how to generate this loop?

The code I used to build this HTML is:

    ![mapa.](D:/IDGeo/Earth analytics course_Learn data science/week 1/ana.png)
    {r label, echo=FALSE, message=FALSE}
    setwd("D:/IDGeo/Earth analytics course_Learn data science/week 1")
    library(knitr)
    library(tidyverse)
    library(gghighlight)
    library(dplyr)
    library(plotly)
    theme_set(theme_bw())

    tabela<-read.csv2("p1.csv", h=TRUE, dec=",")
    #Definning mean values for x and y
    x_mid<- mean(tabela$nota, na.rm = TRUE)
    y_mid<- mean(tabela$classe, na.rm = TRUE)

    #Graph with highlighted point
    df<-tabela %>% mutate(name = row.names(.))
    df %>%
    mutate(quadrant = case_when(nota > x_mid & classe > y_mid   ~ "Q1",
                              nota <= x_mid & classe > y_mid  ~ "Q2",
                              nota <= x_mid & classe <= y_mid ~ "Q3",
                              TRUE                            ~ "Q4")) %>%   
    #df %>%  
    ggplot(aes(nota,classe)) +
    geom_point(col="darkred") +
    gghighlight(nota == 2,
                unhighlighted_colour = alpha("steelblue", 0.4),
                use_direct_label = TRUE,
                label_key = nome,
                label_params = list(size = 5)) +
    geom_vline(xintercept = x_mid) + 
    geom_hline(yintercept = y_mid) +
    geom_point(col="darkred", sixe = 2.5)

    #General areas graph

    x <- c(tabela$classe)
    y <- c(tabela$area)
    data <- data.frame(x, y)

    barra <- plot_ly(data, x = ~x, y = ~y, type = 'bar', color = I("black")) %>%
    layout(title = "Features",
         xaxis = list(title = ""),
         yaxis = list(title = ""))
    barra
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • It's difficult to give a detailed answer without having a [reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). If you can provide a small sample dataset it will be easier for people to help you. In general terms though, using `rmarkdown::render` within a for loop should allow you to produce many reports, one for each value. There are a few questions on stack that might help e.g. [here](https://stackoverflow.com/questions/30422008/r-knitr-pdf-is-there-a-posssibility-to-automatically-save-pdf-reports-generate/30512430#30512430). – joshpk Sep 16 '19 at 20:48
  • Hi, @Trenton_M, thanks for your support, this is the file containning the sample html plus the sample csv. https://1drv.ms/u/s!AhWR0z2EmmmykA9prnOWDAIkh_66?e=5x65Lb I just look through the answer that you suggested, however it does not correspond to what I'm looking for, since in that sample there are no graphs or images... If you need more something to help me, just let me know. Thank you very much! – Ana Paola Siri Sep 18 '19 at 13:26
  • Look into [parameterized reports in the RMarkdown book](https://bookdown.org/yihui/rmarkdown/params-declare.html). I don't have a specific answer for you, but this might point you in the direction. – mpe Sep 26 '19 at 11:30

0 Answers0