Forum Discussion
Anonymous
6 years agoNot applicable
Error in Custom Visual in R because not interacting with my powerbi's filters
I have an error in the custom visula in R because this graphic does not interact or update with the filters of my power BI, can someone help me to solve this problem. In the following image is the graph that I made and the code of R. Thank you very much.
The code is in R
source('./r_files/flatten_HTML.r')
############### Library Declarations ###############
libraryRequireInstall("ggplot2");
libraryRequireInstall("plotly")
libraryRequireInstall("reshape2")
libraryRequireInstall("deSolve")
libraryRequireInstall("gridExtra")
####################################################
################### Actual code ####################
simulate <- function(theta,init.state,times) {
ode <-function(t,x,params){
S<-x[1]
E<-x[2]
I<-x[3]
R<-x[4]
A<-x[5]
H<-x[6]
with(as.list(params),{
N=S+E+I+R+A+H
dS <- -b*S*(I+A)/N
dE <- b*S*(I+A)/N - E/De
dI <- r*E/De - I/Di
dA <- (1-r)*E/De - A/Di
dH <- a*I/Dq + a*A/Dq - H/Dh
dR <- (1-a)*(I+A)/Di + H/Dh
dx <- c(dS,dE,dI,dR,dA,dH)
list(dx)
})
}
traj <- as.data.frame(lsoda(init.state, times, ode, theta))
return(traj)
}
init.state <- c(S=sum(50000000),E=346,I=80,R=0,A=0,H=0)
theta <- c(b=1.75,De=5.2,Di=2.3,Dq=10,Dh=30,r=0.19,a=0.2)
times <- rep(1:100)
x <- simulate(theta,init.state,times)
x2 <- x[,-c(5,2)]
### FIGURES
# melt the data to a long format
df2 <- melt(data = x2, id.vars = "time")
# plot, using the aesthetics argument 'colour'
g<-ggplot(data = df2, aes(x = time, y = value, colour=variable)) + geom_line()+
labs(colour = "Poblaciones")+
xlab("Tiempo") +
ylab("Pob")
####################################################
############# Create and save widget ###############
p = ggplotly(g);
internalSaveWidget(p, 'out.html');
####################################################
4 Replies
- Greg_DecklerCommunity Champion
I don't believe R visuals support cross filter?
- AnonymousNot applicable
Greg_Deckler dm-p That means that the custom graphics in R are static, do not vary with the filters?
- Greg_DecklerCommunity Champion
Well, this one does in fact cross filter (see attached) so perhaps it has to do with your R Script and whether or not it is using the default data frame.