在 Power BI 服务中创建 R 视觉对象Creating R visuals in the Power BI service

Power BI 服务支持查看使用 R 脚本创建的视觉对象并与之交互。The Power BI service supports viewing and interacting with visuals created with R scripts. 使用 R 脚本创建的视觉对象通常称为 R 视觉对象 ,它可以借助 R 丰富的分析和可视化功能来显示高级数据成型和分析(如预测)。Visuals created with R scripts, commonly called R visuals, can present advanced data shaping and analytics such as forecasting, using the rich analytics and visualization power of R.

备注

R 编程语言是统计学家、数据科学家和业务分析师使用最广泛的一种编程语言。The R programming language is among the most widely used programming languages by statisticians, data scientists, and business analysts. R 语言有一个开放源代码社区,该社区提供超过 7000 个加载项包以及广泛使用的 R 用户组。The R language has an open source community that offers over 7,000 add-on packages, as well as widely used R User Groups. Power BI 服务中部署的 R 版本为 Microsoft R 3.4.4 。The version of R deployed in the Power BI service is Microsoft R 3.4.4.

下图显示了一个 Power BI 仪表板,其中包含一组用于高级分析的 R 视觉对象。The following image shows a Power BI dashboard with a collection of R visuals used for advanced analytics.

R 视觉对象在 Power BI Desktop 报表中创建,例如下图所示的报表。R visuals are created in a Power BI Desktop report, like the report shown in the following image.

Power BI Desktop 中生成报表后,便可将包含一个或多个 R 视觉对象的报表发布到 Power BI 服务。Once the report is created in Power BI Desktop, you can publish the report containing one or more R visuals to the Power BI service. R 视觉对象暂时只能在 Power BI Desktop 中创建,然后发布到 Power BI 服务。R visuals currently can only be created in Power BI Desktop, and then published to Power BI service. 有关创建 R 视觉对象的详细信息,请参阅使用 R (Power BI Desktop) 创建 Power BI 视觉对象For more information on creating R visuals, see Create Power BI visuals using R (Power BI Desktop).

请注意,该服务并不支持所有 R 程序包。Note that in the service not all of the R packages are supported. 有关 Power BI 服务当前支持的程序包的列表,请参阅本文末尾的“支持的程序包”。See supported packages at the end of this article for the list of packages currently supported in the Power BI service.

你可以下载这个包含数个 R 视觉对象的 Power BI Desktop 示例文件(.pbix 文件),以了解其工作原理并进行试验。You can download this sample Power BI Desktop file (.pbix file) that contains a few R visuals to see how this works, and to experiment.

对于在 Power BI Desktop 中创建,然后发布到 Power BI 服务的 R 视觉对象,其行为很大程度上与 Power BI 服务中的其他任何视觉对象类似;你可以与之进行交互,对其进行筛选和切分,还可以将其固定到仪表板,或与他人共享。R visuals that are created in Power BI Desktop, and then published to the Power BI service, for the most part behave like any other visual in the Power BI service; you can interact, filter, slice, and pin them to a dashboard, or share them with others. 有关共享仪表板和视觉对象的详细信息,请参阅与同事和其他人共享仪表板For more information about sharing dashboards and visuals, see share a dashboard with colleagues and others. 与其他视觉对象的不同之处在于,R 视觉对象不能显示工具提示,并且不能用于筛选其他视觉对象。One difference from other visuals is that R visuals cannot show tool tips and cannot be used to filter other visuals.

如下图所示,无论是在仪表板还是报表中,Power BI 服务中的 R 视觉对象的外观和行为很大程度上都与任何其他视觉对象类似,用户无需了解创建该视觉对象的基础 R 脚本。As you can see in the following image, R visuals in the Power BI service, either in dashboards or reports, largely appear and behave like any other visual, and users don't need to be aware of the underlying R script that created the visual.

R 脚本安全性R scripts security

R 视觉对象是根据 R 脚本创建的,其中可能包含具有安全风险或隐私风险的代码。R visuals are created from R scripts, which could potentially contain code with security or privacy risks.

当脚本作者在其自己的计算机上运行脚本时,这些风险主要存在于创作阶段。These risks mainly exist in the authoring phase when the script author run the script on their own computer.

Power BI 服务应用了 沙盒 技术,可使用户和服务远离安全风险。The Power BI service applies a sandbox technology to protect users and the service from security risks.

这种 沙盒 方法会对 Power BI 服务中运行的 R 脚本施加一些限制,例如不能访问 Internet,或者不能访问创建 R 视觉对象时无需使用的其他资源。This sandbox approach imposes some restrictions on the R scripts running in the Power BI service, such as accessing the Internet, or accessing to other resources that are not required to create the R visual.

R 脚本错误体验R scripts error experience

如果 R 脚本发生错误,则不会绘制 R 视觉对象,并且将显示一条错误消息。When an R script encounters an error, the R visual is not plotted and an error message is displayed. 若要查看该错误的详细信息,请从画布上的 R 视觉对象错误中选择“查看详细信息” ,如下图所示。For details on the error, select See details from the R visual error on the canvas, as shown in the following image.

再举一个例子,下图显示的是当 R 脚本因为在 Azure 中缺少某个 R 程序包而无法正常运行时出现的错误消息。As another example, the following image shows the error message that appears when an R script failed to run properly due to a missing R package in Azure.

许可Licensing

R 视觉对象需要 Power BI Pro 许可证,才能在报表中呈现、刷新、筛选和交叉筛选。R visuals require a Power BI Pro license to render in reports, refresh, filter and cross-filter. 有关 Power BI Pro 许可证及其与免费许可证的区别的详细信息,请参阅 Power BI Pro 内容 — 它是什么?For more information about Power BI Pro licenses, and how they differ from free licenses, see Power BI Pro content - what is it?

Power BI 的免费用户只能使用在 Premium 工作区中与其共享的磁贴。Free users of Power BI can only consume tiles shared with them in Premium workspaces. 有关详细信息,请参阅购买 Power BI ProSee purchasing Power BI Pro for more information.

下表介绍了基于授权的 R 视觉对象功能。The following table describes R visuals capabilities based on licensing.

在 Power BI Desktop 中创作 R 视觉对象Author R visuals in Power BI Desktop 使用 R 视觉对象创建 PBI 服务报表Create PBI service reports with R visuals 查看报表中的 R 视觉对象View R visuals in reports 查看仪表板中的 R 磁贴View R tiles in dashboards
来宾 (Power BI Embedded)Guest (Power BI embedded) 支持Supported 不支持Not supported 仅在高级容量/Azure 容量中受支持Supported in Premium/Azure capacity only 仅在高级容量/Azure 容量中受支持Supported in Premium/Azure capacity only
非托管租户(域未验证)Unmanaged tenant (domain not verified) 支持Supported 不支持Not supported 不支持Not supported 支持(B2B 方案)Supported (B2B scenario)
具有免费许可证的托管租户 Managed tenant with free license 支持Supported 不支持Not supported 仅高级容量中受支持Supported in Premium capacity only 支持Supported
具有 Pro 许可证的托管租户 Managed tenant with Pro license 支持Supported 支持Supported 支持Supported 支持Supported

已知限制Known Limitations

Power BI 服务中的 R 视觉对象有几个限制:R visuals in the Power BI service have a few limitations:

  • R 视觉对象支持仅适用于以下页面 上标识的程序包。R visuals support is limited to the packages identified on the following page . 目前不提供对自定义程序包的支持。There currently is no support for custom packages.

  • 数据大小限制 - R 视觉对象用于绘制的数据仅限 150,000 行。Data size limitations – data used by the R visual for plotting is limited to 150,000 rows. 如果选择了 150,000 行以上,则只会使用前 150,000 行,且在图像上显示一条消息。If more than 150,000 rows are selected, only the top 150,000 rows are used and a message is displayed on the image.

  • 计算时间限制 — 如果 R 视觉对象计算时间超过 60 秒,则脚本将超时,从而导致错误。Calculation time limitation – if an R visual calculation exceeds 60 seconds the script times out, resulting in an error.

  • R 视觉对象在数据更新、筛选和突出显示时进行刷新。R visuals are refreshed upon data updates, filtering, and highlighting. 但是,图像本身不可交互,并且不支持工具提示。However, the image itself is not interactive and does not support tool tips.

  • R 视觉对象响应突出显示的其他视觉对象,但你不能单击 R 视觉对象中的元素以进行其他元素的交叉筛选。R visuals respond to highlighting other visuals, but you cannot click on elements in the R visual in order to cross filter other elements.

  • R 视觉对象目前不支持 时间 数据类型。R visuals are currently not supported for the Time data type. 请改为使用日期/时间。Please use Date/Time instead.

  • 使用“发布到 Web” 时,不会显示 R 视觉对象。R Visuals do not display when using Publish to web.

  • R 视觉对象目前不会随仪表板和报表一起打印R visuals currently do not print with dashboard and reports printing

  • Analysis Services 的 DirectQuery 模式目前不支持 R 视觉对象R visuals are currently not supported in the DirectQuery mode of Analysis Services

  • 中文、日语和朝鲜语字体需要执行以下所有附加步骤才能在 Power BI 服务中正常工作:Chinese, Japanese and Korean fonts require all of the additional following steps to work properly in the Power BI service:

    • 首先,安装 R 程序包 showtext 及其所有依赖项。First, install the R package showtext and all of its dependencies. 可以运行以下脚本来执行此操作:You can do this by running the following script:

      *install.packages("showtext")*
      
    • 接下来,在 R 脚本的开头添加以下行:Next, add the following line at the beginning of the R script:

      powerbi_rEnableShowTextForCJKLanguages =  1
      

R 程序包概述Overview of R packages

R 程序包是以定义明确的格式组合的 R 函数、数据和已编译代码的集合。R packages are collections of R functions, data, and compiled code that are combined in a well-defined format. 安装 R 后,会生成标准的程序包集,其他程序包可供下载和安装。When R is installed, it comes with a standard set of packages, and other packages are available for download and installation. 安装后,必须将 R 程序包加载到要使用的会话中。Once installed, an R packages must be loaded into the session to be used. 免费 R 程序包的主要源是 CRAN,即 Comprehensive R Archive NetworkThe primary source of free R packages is CRAN, the Comprehensive R Archive Network.

Power BI Desktop 可以使用任意类型的 R 程序包,且没有任何限制。Power BI Desktop can use any type of R packages without limitation. 可以自行安装 R 程序包用于 Power BI Desktop(例如,使用 RStudio IDE)。You can install R packages for use in Power BI Desktop on your own (using the RStudio IDE, for example).

本文中介绍的“支持的程序包”部分中的程序包支持“Power BI 服务”中的 R 视觉对象。R visuals in the Power BI service are supported by the packages found in the Supported Packages section found in this article. 如果在支持的程序包列表中未找到所需的程序包,可以请求获得所需程序包的支持。If you don't find a package you're interested in among the supported packages list, you can request the support of the package. 请参阅 Power BI 服务中的 R 程序包,了解有关如何请求支持的信息。See R packages in the Power BI service for information on how to request support.

R 程序包要求和限制Requirements and Limitations of R packages

R 程序包存在大量要求和限制:There are a handful of requirements and limitations for R packages:

  • Power BI 服务主要支持带有免费和开源软件许可证(例如 GPL-2、GPL-3、MIT+R 等)的 R 程序包.The Power BI service, for the most part, supports R packages with free and open-source software licenses such as GPL-2, GPL-3, MIT+, and so on.

  • Power BI 服务支持已在 CRAN 发布的程序包。The Power BI service supports packages published in CRAN. 此服务不支持专用或自定义 R 程序包。The service does not support private or custom R packages. 我们鼓励用户请求在 Power BI 服务中公开发布其专用程序包前,先将程序包在 CRAN 上公开发布。We encourage users to make their private packages available on CRAN prior to requesting the package be available in the Power BI service.

  • Power BI Desktop 具有两种 R 程序包变体:For Power BI Desktop has two variations for R packages:

    • 对于 R 视觉对象,可以安装任意程序包,包括自定义 R 程序包For R visuals, you can install any package, including custom R packages
    • 对于自定义 R 视觉对象,仅支持公用 CRAN 程序包进行程序包自动安装For Custom R visuals, only public CRAN packages are supported for auto-installation of the packages
  • 出于安全和隐私考虑,服务当前不支持通过万维网提供客户端到服务器查询的 R 程序包(例如 RgoogleMaps)。For security and privacy reasons, we currently don't support R packages that provide client-server queries over the World-Wide Web (such as RgoogleMaps) in the service. 系统会阻止联网进行此类尝试。Networking is blocked for such attempts. 请参阅 Power BI 服务中的 R 程序包,了解有关受支持和不受支持的 R 程序包的列表。See R packages in the Power BI service for a list of supported and unsupported R packages.

  • 纳入新的 R 程序包的审核流程具有一系列的依赖项;需要在服务中安装的某些依赖项不受支持。The approval process for including a new R package has a tree of dependencies; some dependencies required to be installed in the service cannot be supported.

支持的程序包:Supported Packages:

对于受支持的 R 程序包的长列表(以及不受支持的程序包的短列表),请参阅以下文章:For a long list of supported R packages (and the short list of unsupported packages) please see the following article: