简体   繁体   中英

Use R script to refresh data in Power BI: Maximize Power-BI pre-built visuals and R's computational power

Let's say I have a very simple R script which does the following: It creates a new 'y' column by applying Sine function to column x. The result of this dataframe is then stored as csv. Example below I name this new dataset R_Calculated_Table.csv

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

# dataset <- data.frame(x)
# dataset <- unique(dataset)

# Paste or type your script code here:
dataset$y <- sin(dataset$x)
write.csv(dataset, 'C:/Users/User1/Desktop/R_Calculated_Table.csv')

This R_Calculated_Table csv file is being as a source for Power BI visuals. In this example, I want to simply plot how x varies with the Sine function.

Now let's say I change the function from Sine to Tangent. R will then replace the R_Calculated_Table.csv whenever I run the script.

However the Power BI visual will not be updated until I right click on ' R_Calculated_Table ' and click 'Refresh Data'. Upon refresh, I can now see how does tangent function will look like because the visual will be updated.

The problem here is, I need to somehow right click and refresh the data source. Is it possible to somehow trigger Power BI to refresh the data each time the R script is triggered instead of manually right-clicking on the source table to get it refreshed?

Below screenshot is where I use R script to calculate Sine values

在此处输入图像描述

Ideally, I want the user to be able to choose and select the function they want to see. R will do the computation and Power BI will pick up the updated CSV file and visualize the data.

Is this doable in Power BI?

To abstract this problem, what I want in the end is to maximize the usage of Power BI built-in visuals and at the same time take advantage of R's powerful computational capabilities .

R visuals are limited in interactivity because my end users expect to be able to 'Export data' from the visuals. They also want the tool tip to be present.

Of course for more complex visualizations which make use ggplot features, it's not possible to replicate in Power BI.

No, it not possible in Power BI Desktop to automatically refresh or schedule a refresh. In your requirement you are loading a dataset, re-writing it out, then it will have to be manual refresh to load it and then display the new dataset.

It may be possible to do this in a coming version of Power BI Desktop , If you write back to a location, then you will may be able to set a refresh in the desktop, details are limited, but Microsoft have shown it in use with a database as a datasource, but it will be based on time, not an event like a file write.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM