Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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');
####################################################
I don't believe R visuals support cross filter?
@Greg_Deckler @dm-p That means that the custom graphics in R are static, do not vary with the filters?
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.
Hi @Anonymous
All custom visuals by default will take cross-filtered data from slicers or other visuals into their dataView. You can verify this by clicking the ellipsis (...) on the visual container and choosing 'Show as a table' both before and after applying a slicer or cross-filter and see the differences.
I don't do my custom visual development in R, nor am I currently set up for it in my dev environment but I've reviewed your code and a number of tutorials online and I think the issue is that your visual isn't actually binding to any data from your data model and just using static data.
The default data frame passed in from Power BI to your visual has a default name of Values, and you'll need to work with that object to make the data in your visual respond to changes in filter context within your report.
This name is defined in capabilities.json in your project, e.g.:
...
"dataRoles": [
{
"displayName": "Values",
"kind": "GroupingOrMeasure",
"name": "Values" <---- This one right here
}
],
...
So, provided you haven't renamed this if you reference the Values data frame in your code, that should be all there is to it.
Further reading:
Good luck!
Daniel
Proud to be a Super User!
My course: Introduction to Developing Power BI Visuals
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
User | Count |
---|---|
15 | |
2 | |
1 | |
1 | |
1 |
User | Count |
---|---|
18 | |
11 | |
5 | |
4 | |
3 |