Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
andrnev
Regular Visitor

R script not reacting to change in selection

Hi, I have created two R scripts script1 and script2

 

script1 saves the dataframe using saveRDS function into a local directory

script2 reads the saved dataframe and displays the data.

 

The problem is that script1 reacts to a selection I make via a "slicer" dropdown but script2 does not. Only after manually running script2 by clicking "run script" button do I get a reaction. Any idea how I could trigger script2 to react to the changed script1's saved data?

 

Code of script1

 

library(gridExtra) # Displaying data onto Power BI Desktop
library(dplyr) # For data munging

pathToProject <-"F:\\PowerBiDocuments\\"
df1 <- group_by(dataset, manufacturer) %>% summarise('avg_cty_mileage' = mean(cty), 'avg_hwy_mileage' = mean(hwy))
saveRDS(df1, paste0(pathToProject,"df1"))

Code of script2

 

require(gridExtra)
require(ggplot2)
pathToProject <- "F:\\PowerBiDocuments\\"
df2 <- readRDS(paste0(pathToProject,"df1"))
grid.table(df2)

 

1 ACCEPTED SOLUTION
v-sihou-msft
Employee
Employee

@andrnev

 

No, it's not possible. You must click the "run script" or click "Refresh" to make the R visual take the slicer selection and execute the script again. You may create a feature request on idea.

 

Regards,

 

View solution in original post

6 REPLIES 6
TomMartens
Super User
Super User

Hey,

 

I just curious, why can't you just combine both scripts into one like so

 

library(gridExtra) # Displaying data onto Power BI Desktop
library(dplyr) # For data munging

df1 <- group_by(dataset, manufacturer) %>% summarise('avg_cty_mileage' = mean(cty), 'avg_hwy_mileage' = mean(hwy))
grid.table(df1)

Regards

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Well if I wanted to modify the data within script 2 and display both script 1 original data and script2 modified data then script 2 should understand that it needs to 'react' only after script 1 completes. Running script 1 first and then manually running script2 ensures the hierarchy is maintained I.e. script1 has to run first and then script2 will pull in the modified script1 data and further modifies it. If there was a way in power bi to maintainthis hierarchial triggering with reactivity it would be super.

Hey,

 

I'm not sure if this will help, but maybe you are not aware of the function "grid.arrange"

 

This little script

library(ggplot2)
library(gridExtra)

df <- data.frame(cat = c("A", "B"), amount = c(110, 120))


p1 <- ggplot()
p1 <- p1 + geom_col(data = df, aes(x = cat, y = amount))

# here starts the modification of the data.frame df that than can used with the function tableGrob
# create a grob (graphical object) from a data frame p2 <- tableGrob(df)
# this creates a single plot that contains "two different plots" that also can be arranged in almost
# any way you want use ?grid.arrange to the documentation of grid.arrange grid.arrange(p1, p2)

creates this output

 

multiple plots.png

Maybe this is what you are looking for

 

Regards Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Tom many thanks. Yes I did look at the grid.arrange. it definitely is one workaround solution. I guess I was looking for a more azure way of doing things where we can just plug in models. Would be a great feature to have.
v-sihou-msft
Employee
Employee

@andrnev

 

No, it's not possible. You must click the "run script" or click "Refresh" to make the R visual take the slicer selection and execute the script again. You may create a feature request on idea.

 

Regards,

 

ThanksSimon. I asked for the feature on the ideas section.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.