繁体   English   中英

使用 Power BI 中的 Office 数据连接 (.odc) 文件连接到 R 中的数据库

[英]connecting to a database in R using an Office Data Connection (.odc) file from Power BI

我被要求为一个大型组织制作一堆图表,并获得了访问他们的 Power BI 仪表板的权限。 我想在 Power BI 的界面周围做 go,这样我就可以在 R 中制作图表。 Power BI 提供“在 excel 中分析”选项,您可以下载一个 .odc 文件以在 excel 中打开。 .odc 文件不包含它只是为 excel 指定数据库连接的数据。 但是,这只适用于 windows 计算机,我有一台 mac。 如果需要,我会尝试弄清楚如何安装 Windows 虚拟机,但我想我会先在这里尝试:

.odc 文件指定连接类型和字符串,例如

<odc:Connection odc:Type="OLEDB">   
<odc:ConnectionString>Provider=MSOLAP;Integrated Security=ClaimsToken;
Identity Provider=https://login.microsoftonline.com/common, 
https://analysis.windows.net/powerbi/api, 929d0ec0-7a41-4b1e-bc7c-b754a28bddcc;
Data Source=pbiazure://api.powerbi.com;
Initial Catalog=2df8e9ba-9ee5-43fb-bbb0-ba622b9cdc2b;
MDX Compatibility= 1; MDX Missing Member Mode= Error; 
Safety Options= 2; Update Isolation Level= 2; </odc:ConnectionString>

我希望可以使用dbplyr或其他一些 package 连接到 R 中的底层数据库,但我不确定从哪里开始。 This answer for how to do it in python looks promising Reading a dataframe from an odc file created through excel using pandas but I got an error relating to my python installation. 我宁愿让它在 R 中工作。

.odc 文件中是否有足够的信息可以通过dbplyr进行连接?

您在问题中发布的内容似乎是 Azure 数据库的 OLE DB 连接字符串。 连接字符串特定于您正在连接的源(例如 Azure 或 SQL),而不是正在连接的程序(例如 R 或 Power BI)。

但是 R 和dbplyr似乎主要与 ODBC 连接而不是 OLE DB ( 参考 1参考 2 )一起使用。

您可以使用链接将 OLE DB 连接字符串转换为 ODBC 连接字符串。 但是,这确实需要源接受/具有 ODBC 连接的驱动程序。

我建议首先检查是否有可用的 ODBC 连接,因为这样会简单得多。

一旦你有一个连接字符串,连接到源应该像这样运行:

connection_string <- "DRIVER=...; DATABASE=...; SERVER=...;"
db_connection <- DBI::dbConnect(odbc::odbc(),. connection_string = connection_string)
remote_table <- dplyr::tbl(db_connection, from = "name_of_remote_table")

暂无
暂无

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

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