简体   繁体   English

使用 R 脚本刷新 Power BI 中的数据:最大化 Power-BI 预构建的视觉效果和 R 的计算能力

[英]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.假设我有一个非常简单的 R 脚本,它执行以下操作:它通过将 Sine function 应用于 x 列来创建一个新的 'y' 列。 The result of this dataframe is then stored as csv.然后将 dataframe 的结果存储为 csv。 Example below I name this new dataset R_Calculated_Table.csv下面的示例我将此新数据集命名为 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.R_Calculated_Table csv 文件用作 Power BI 视觉对象的来源。 In this example, I want to simply plot how x varies with the Sine function.在这个例子中,我想简单地说明 plot x 如何随正弦 function 变化。

Now let's say I change the function from Sine to Tangent.现在假设我将 function 从 Sine 更改为 Tangent。 R will then replace the R_Calculated_Table.csv whenever I run the script.每当我运行脚本时,R 将替换R_Calculated_Table.csv

However the Power BI visual will not be updated until I right click on ' R_Calculated_Table ' and click 'Refresh Data'.但是,在我右键单击“ R_Calculated_Table ”并单击“刷新数据”之前,Power BI 视觉对象不会更新。 Upon refresh, I can now see how does tangent function will look like because the visual will be updated.刷新后,我现在可以看到切线 function 的样子,因为视觉效果将被更新。

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?是否可以在每次触发 R 脚本时以某种方式触发 Power BI 刷新数据,而不是手动右键单击源表以使其刷新?

Below screenshot is where I use R script to calculate Sine values下面的屏幕截图是我使用 R 脚本计算正弦值的地方

在此处输入图像描述

Ideally, I want the user to be able to choose and select the function they want to see.理想情况下,我希望用户能够选择他们想看到的 select 和 function。 R will do the computation and Power BI will pick up the updated CSV file and visualize the data. R 将执行计算,Power BI 将获取更新的 CSV 文件并可视化数据。

Is this doable in Power BI?这在 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 .把这个问题抽象出来,我最终想要的是最大限度地利用Power BI内置的视觉效果,同时利用R强大的计算能力

R visuals are limited in interactivity because my end users expect to be able to 'Export data' from the visuals. R 视觉效果的交互性有限,因为我的最终用户希望能够从视觉效果中“导出数据”。 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.当然,对于使用 ggplot 功能的更复杂的可视化,不可能在 Power BI 中复制。

No, it not possible in Power BI Desktop to automatically refresh or schedule a refresh.不,在 Power BI Desktop 中无法自动刷新或计划刷新。 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.即将发布的 Power BI Desktop 版本中可能会执行此操作,如果您回写到某个位置,那么您可能可以在桌面中设置刷新,细节有限,但微软已经展示了它与数据库作为数据源,但它将基于时间,而不是像文件写入这样的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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