Hi, I am about to render all of the graphs in HTML (interactive version) using saveWidget command.
Here is my data description: I got multiple pigs, each has its own ID. They have a set of data referenced back to the pig ID. I want to plot this data and save each graph of each pig to a html file.
SO far, I can only do one pig at once and I want to do it for all pig ID. Here is my codebase:
#Set working directory
setwd("C:/Users/Kevin Le/PycharmProjects/R_project")
#load data after data treatment
load("JRPData.Rdata")
#----------------------------------------------------
# Attribute new easier name to each column
#----------------------------------------------------
#Order number of Animal_ID
ID <- unique(JRP_NA$ANIMAL_ID)
#Pig ID
Pig_ID <- JRP_NA$ANIMAL_ID
#Age (days)
Age <- JRP_NA$AGE
#Daily Feed Intake (kg)
DFI <- JRP_NA$FEED_INTAKE
for(idc in seq_along(ID)){
# extract data for animal i
i <- ID[idc] # 90
#extract dataset for animal i
Data <- JRP_NA.0[JRP_NA.0$ANIMAL_ID == i,]
Data
#Age vector associated with
Age.plot <- Age[Pig_ID == i]
#DFI vector associated with animal i
DFI.plot <- DFI[Pig_ID == i]
# Plot DFI graph
# tiff(file = paste0("C:/Users/Kevin Le/PycharmProjects/R_project/Graphs/Step0_graphs/", idc, ".", Data$ANIMAL_ID, ".", "DFI", ".png"), width = 6000, height = 3500, units = "px", res=600)
D <- plot_ly(Data, x = Age.plot, y = DFI.plot , type = 'scatter', mode = 'markers')%>%
layout(title = paste("Daily feed intake measured from an auto-feeder","\nPig ID:", ID[idc]), plot_bgcolor = "#e5ecf6", xaxis = list(title = 'Age, d'),
yaxis = list(title = 'Daily Feed Intake, kg/ d'))
saveWidget(D, file="myFile.html")
}
As you can see, I can only export it into a file name:myFile.html. Now, I want to export the htl graph file for all pig ID , each have their own file.