在 Power BI 中使用 R 提供技術的自訂視覺效果Use R-powered custom visuals in Power BI

Power BI DesktopPower BI 服務中,您不必具備任何 R 的知識或編寫任何 R 指令碼,就能使用 R 提供技術支援的自訂視覺效果。In Power BI Desktop and the Power BI service, you can use R-powered custom visuals without any knowledge of R, and without any R scripting. 這讓您能夠充分運用 R 視覺效果的分析與視覺效果功能及 R 指令碼,而不必親自學習 R 或設計程式。This enables you to harness the analytic and visual power of R visuals, and R scripts, without learning R or doing any programming yourself.

若要使用 R 提供技術的自訂視覺效果,您必須先從 AppSource 的 Power BI 自訂視覺效果資源庫選取並下載想要使用的 R 自訂視覺效果。To use R-powered custom visuals, you first select and download the R custom visual you're interested in using from the AppSource gallery of custom visuals for Power BI.

下列章節描述如何選取、載入以及在 Power BI Desktop 使用由 R 提供技術的視覺效果。The following sections describe how to select, load, and use R-powered visuals in Power BI Desktop.

使用 R 自訂視覺效果Use R custom visuals

若要使用 R 提供技術的自訂視覺效果,您必須從自訂視覺效果資源庫下載各項視覺效果,然後在 Power BI Desktop 如同其他任何視覺效果類型般使用該視覺效果。To use R-powered custom visuals, you need to download each visual from the custom visuals library, then you can use the visual like any other type of visual in Power BI Desktop. 取得自訂視覺效果的方法有兩種 - 您可以從線上 AppSource 網站下載,或在 Power BI Desktop 中瀏覽並取得。There are two ways to get custom visuals - you can download them from the online AppSource site, or you browse and get them from within Power BI Desktop.

從 AppSource 取得自訂視覺效果Get custom visuals from AppSource

以下步驟說明如何從線上 AppSource 網站瀏覽並選取視覺效果:Here are the steps to browse and select visuals from the online AppSource site:

  1. 瀏覽至 Power BI 視覺效果資源庫,位置在 https://appsource.microsoft.com。選取「依產品縮小搜尋範圍」下的 [Power BI 應用程式],然後選取 [查看全部] 連結。Navigate to the Power BI visuals library, found at https://appsource.microsoft.com. Select the Power BI apps checkbox under Refine by product, then select the See all link.

  2. 從左方窗格的增益集清單中選取 [Power BI 視覺效果]。Select Power BI visuals from the list of Add-ins in the left pane.

  1. 從資源庫選取您想要使用的視覺效果,就會前往視覺效果的說明頁面。Select the visual you're interested in using from the gallery, and you're taken to a page that describes the visual. 選取 [立即取得] 按鈕即可下載。Select the Get it now button to download.

    注意

    若要在 Power BI Desktop 中撰寫,您必須將 R 安裝在本機電腦上。For authoring in Power BI Desktop, you need to have R installed on your local machine. 但當使用者想要在 Power BI 服務中檢視 R 提供技術的視覺效果時,則「不」需要將 R 安裝在本機。But when users want to view an R-powered visual in the Power BI service they do not need R installed locally.

    您無須先安裝 R 才能在 Power BI 服務中使用 R 提供技術的自訂視覺效果,但是如果您要在 Power BI Desktop 中使用 R 提供技術的自訂視覺效果,則「必須」於本機上安裝 R。You do not need to install R to use R-powered custom visuals in the Power BI service, however, if you want to use R-powered custom visuals in Power BI Desktop you must install R on the local machine. 您可以從下列位置下載 R:You can download R from the following locations:

  2. 下載視覺效果之後 (如同從瀏覽器下載任何檔案),移至 Power BI Desktop 並以滑鼠右鍵按一下 [視覺效果] 窗格中的省略符號 (...),然後選取 [從檔案匯入]。Once the visual is downloaded (which is like downloading any file from your browser), go to Power BI Desktop and right-click the ellipsis (the ...) in the Visualizations pane, and select Import from file.

  3. 您會在匯入自訂視覺效果時收到警告,如下圖所示:You're cautioned about importing a custom visuals, as shown in the following image:

  4. 瀏覽至儲存視覺效檔案的位置,然後選取該檔案。Navigate to where the visual file was saved, then select the file. Power BI Desktop 自訂視覺效果的副檔名為 .pbiviz。Power BI Desktop custom visualizations have the .pbiviz extension.

  5. 當您返回 Power BI Desktop 時,即可在 [視覺效果] 窗格中使用新的視覺效果類型。When you return to Power BI Desktop, you can see the new visual type in the Visualizations pane.

  6. 當您匯入新的視覺效果 (或開啟的報表包含 R 提供技術的自訂視覺效果),Power BI Desktop 會安裝所需的 R 套件。When you import the new visual (or open a report that contains a R-powered custom visual), Power BI Desktop installs the required R packages.

您可以從該位置將資料新增至視覺效果,方式如同其他任何 Power BI Desktop 視覺效果。From there, you can add data to the visual just as you would any other Power BI Desktop visual. 完成時,您會在畫布上看到完成的視覺效果。When complete, you can see your finished visual on the canvas. 在下列視覺效果中,R 提供技術的 [預測] 視覺效果搭配使用聯合國 (UN) 生育率投影 (左側視覺效果)。In the following visual, the Forecasting R-powered visual was used with United Nations (UN) birth rate projections (the visual on the left).

如同其他任何 Power BI Desktop 視覺效果,您可以將此報表及其 R 提供技術的視覺效果一併發佈至 Power BI 服務並與其他人分享。Like any other Power BI Desktop visual, you can publish this report with its R-powered visuals to the Power BI service and share it with others.

由於視覺效果不斷增加,請時常查看資源庫。Check the library often, since new visuals are being added all the time.

Power BI Desktop 中取得自訂視覺效果Get custom visuals from within Power BI Desktop

您也可以從 Power BI Desktop 中取得自訂視覺效果。You can also get custom visuals from within Power BI Desktop. Power BI Desktop 中,於 [視覺效果] 窗格內以滑鼠右鍵按一下省略符號 (...),然後選取 [從市集匯入]。In Power BI Desktop right-click the ellipsis (the ...) in the Visualizations pane, and select Import from store.

當您這樣做時,[Power BI 自訂視覺效果] 對話方塊隨即顯示,您可以在其中捲動檢視可用的自訂視覺效果,並選取您想要的自訂視覺效果。When you do so, the Power BI Custom Visuals dialog appears, where you can scroll through the available custom visuals and select what you would like. 您可以依名稱搜尋、選取類別,或只是捲動檢視可用的視覺效果。You can search by name, select a catagory, or just scroll through the available visuals. 當您準備就緒後,選取 [新增] 即可將自訂視覺效果新增至 Power BI DesktopWhen you're ready, just select Add to add the custom visual to Power BI Desktop.

發表 R 提供技術的自訂視覺效果Contribute R-powered custom visuals

如果您自行建立可用於您報表中的 R 視覺效果,您可在自訂視覺效果資源庫提供該類自訂視覺效果,進而與各地使用者分享。If you create your own R visuals for use in your reports, you can share those visual with the world by contributing your custom visual to the custom visuals gallery. 貢獻會透過 GitHub 進行,程序概述於下列位置:Contributions are made through GitHub, and the process is outlined in the following location:

針對 R 提供技術的自訂視覺效果進行疑難排解Troubleshoot R-powered custom visuals

R 提供技術的自訂視覺效果具有特定相依性,視覺效果必須符合這些相依性才能正常運作。R-powered custom visuals have certain dependencies that must be met for the visuals to work properly. 當 R 提供技術的自訂視覺效果未正確執行或載入時,通常是下列其中一個問題所致:When R-powered custom visuals don't run or load properly, the problem is usually one of the following:

  • R 引擎遺失The R engine is missing
  • 視覺效果所依據的 R 指令碼中發生錯誤Errors in the R script on which the visual is based
  • R 套件遺失或過期R packages are missing or out of date

下一節說明疑難排解步驟,您可執行以協助解決所遇到的問題。The following section describes troubleshooting steps you can take to help address trouble you run into.

R 套件遺失或過期Missing or outdated R packages

嘗試安裝 R 提供技術的自訂視覺效果時,如果 R 套件遺失或過期,您可能會遇到錯誤;這通常是由於下列其中一個原因所致:When attempting to install an R-powered custom visual, you can run into errors when there are missing or outdated R packages; this is usually due to one of the following reasons:

  • R 安裝與 R 套件不相容The R installation is incompatible with the R package,
  • 防火牆、防毒軟體或 Proxy 設定導致 R 無法連線到網際網路A firewall, anti-virus software, or proxy settings are preventing R from connecting to the Internet
  • 網際網路連線速度很慢,或網際網路連線發生問題The Internet connection is slow, or there's an Internet connection problem

Power BI 小組會在連絡您之前主動解決這些問題,下一版 Power BI Desktop 將納入更新以解決這些問題。The Power BI team is actively working on mitigating these issues before they reach you, and the next Power BI Desktop will incorporate updates to address these problems. 在那之前,您可以採取下列一或多個步驟來解決問題:Until then, you can take one or more of the following steps to mitigate the issues:

  1. 移除自訂視覺效果,然後重新安裝。Remove the custom visual, then install it again. 這會起始 R 套件的重新安裝。This initiates a re-installation of the R packages.
  2. 如果您安裝 R 的不是最新版本,請升級您的 R 安裝,然後如上一個步驟所述移除/重新安裝自訂視覺效果。If your installation of R is not current, upgrade your R installation, then remove/re-install the custom visual as described in the previous step.

    • 每個 R 提供技術的自訂視覺效果描述會列出支援的 R 版本,如下圖所示。Supported R versions are listed in the description of each R-powered custom visual, as shown in the following image. > [!NOTE] > 您可以保留原始 R 安裝,只將 Power BI Desktop 與您安裝的目前版本建立關聯。You can keep the original R installation, and only associate Power BI Desktop with the current version you install. 移至 [檔案] -> [選項及設定] -> [選項] > [R 指令碼]。Go to File > Options and settings > Options > R scripting.
  3. 使用任何 R 主控台手動安裝 R 套件。Install R packages manually, using any R console. 此方法的步驟如下所示:The steps for this approach are the following:

    a.a. 下載 R 提供技術的視覺效果安裝指令碼,並將該檔案儲存至本機磁碟。Download the R-powered visual installation script, and save that file to a local drive.

    b.b. 從 R 主控台執行下列命令:From the R console, run the following:

    > source(“C:/Users/david/Downloads/ScriptInstallPackagesForForecastWithWorkarounds.R”)    
    

    一般預設安裝位置如下所示:Typical default installation locations are the following:

    c:\Program Files\R\R-3.3.x\bin\x64\Rterm.exe (for CRAN-R)
    c:\Program Files\R\R-3.3.x\bin\x64\Rgui.exe (for CRAN-R)
    c:\Program Files\R\R-3.3.x\bin\R.exe (for CRAN-R)
    c:\Program Files\Microsoft\MRO-3.3.x\bin\R.exe (for MRO)
    c:\Program Files\Microsoft\MRO-3.3.x\bin\x64\Rgui.exe (for MRO)
    c:\Program Files\RStudio\bin\rstudio.exe (for RStudio)
    
  4. 如果上述步驟沒有作用,請嘗試下列步驟:If the previous steps don't work, try the following:

    a.a. 使用 R Studio 並依照上面 3.b. 中所述的步驟執行Use R Studio and follow the step outlined in 3.b. (從 R 主控台執行指令碼行)。above (run the script line from the R console).

    b.b. 如果上述步驟沒有作用,請在 R Studio 中變更 [工具] > [全域選項] > [套件],並啟用 [Use Internet Explorer library/proxy for HTTP] (針對 HTTP 使用 Internet Explorer 程式庫/Proxy) 核取方塊,然後重複執行If the previous step doesn't work, change Tools > Global Options > Packages in R Studio, and enable the checkbox for Use Internet Explorer library/proxy for HTTP, then repeat step 3.b. 上述步驟中的步驟 3.b。from the above steps.

後續步驟Next steps

請看看下列有關 Power BI 中 R 的其他資訊。Take a look at the following additional information about R in Power BI.