在 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 版本是 Revolution R Open 3.2.2The version of R deployed in the Power BI service is Revolution R Open 3.2.2.

下圖顯示的 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 the Power BI service. 如需有關建立 R 視覺效果的詳細資訊,請參閱 使用 R 建立 Power BI 視覺效果 (Power BI Desktop)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.

您可以下載這份範例 Power BI Desktop 檔案 (.pbix 檔案),其中包含數個 R 視覺效果,可供您查看運作方式及進行實驗。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 指令碼施加某些限制,諸如存取網際網路,或存取建立 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 的免費使用者只能取用共用的磚。Free users of Power BI can only consume tiles shared with them. 如需詳細資訊,請參閱購買 Power BI ProSee purchasing Power BI Pro for more information.

下表依授權說明 R 視覺效果的功能。The following table describes R visuals capabilities based on licensing.

已知的限制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 套件。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. 我們鼓勵使用者先製作其在 CRAN 上可用的私人套件,再要求 Power BI 服務中可用的套件。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. 如需支援與不支援的 R 套件清單,請參閱 Power BI 服務中的 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: