cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jcastro296
Frequent Visitor

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.

contagio.PNG

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 4
Super User IV
Super User IV

Re: Error in Custom Visual in R because not interacting with my powerbi's filters

I don't believe R visuals support cross filter?


---------------------------------------

Not the Power BI thought police...

I have NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

jcastro296
Frequent Visitor

Re: Error in Custom Visual in R because not interacting with my powerbi's filters

@Greg_Deckler @dm-p That means that the custom graphics in R are static, do not vary with the filters?

Super User IV
Super User IV

Re: Error in Custom Visual in R because not interacting with my powerbi's 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.


---------------------------------------

Not the Power BI thought police...

I have NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Super User I
Super User I

Re: Error in Custom Visual in R because not interacting with my powerbi's filters

Hi @jcastro296

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors