Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Pedro-Pereira
Advocate I
Advocate I

R visual connecting to MySQL database

Hi,

 

In summary, I need to be able to connect to a database trought an R visual in power BI service. My code works in the desktop but in the service it doesnt work anymore. When I use the IP adress I have the following error: [ DBI Error in .local(drv, ...) : Failed to connect to database: Error: Can't connect to MySQL server on '(ip adress)' (0)  ]

When I use the host name I have the following error: [ DBI Error in .local(drv, ...) : Failed to connect to database: Error: Unknown MySQL Server Host '(host name)' (11001)  ]

 

Further explanation:

 

My objective is to create a custom R visual in power BI and publish my report with it on power BI service. My visual, is similar to a heat map, but diferent enough that the ones availabe in the store (heatmap, mapbox, esri, etc) don't work for me.

For this map I need both my data points and data from a shapefile. I tried importing both data to power bi but R only accepts 1 dataframe. Joining both tables in power BI doesn´t make that much sense and PowerBI limits it to the top 150k rows (the SHP has 3M rows). As a workaround , that worked in the desktop version, I would like to grab the Shapefile data from a database directly from my R code with dbConnect and fetch (DBI package that is accepted).

 

I'm open to both alternatives to solve this problem or a way to fix this issue, if it is possible

 

Thank you in advance

6 REPLIES 6
zoloturu
Memorable Member
Memorable Member

Hi @Pedro-Pereira,

 

R scripts are not supported in a web version of Power BI currently. You can vote for this idea here - https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/17899522-support-r-visuals-to-pub...

 

Regards,
Ruslan
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!

Hi Ruslan ( @zoloturu ) , thanks for your reply
That vote seems to be a really interesting feature to add to power BI. However, I wasn't looking that further ahead. Right now I only need my R visual to work on app.powerbi.com. I tested some simple visuals and they work but my complex ones only work on desktop.
Do you understand my problem and if so do you know how to fix it?

Also can you please tell me where did you get the idea that I wanted to "publish to web" so that I can edit my post to not confuse other people.

 

Best regards

Pedro

Hi @Pedro-Pereira,

 

Sorry, I missed that R is supported already in Service. I've checked that for you. Here is a link - https://docs.microsoft.com/en-us/power-bi/visuals/service-r-visuals, where you can find all the limitations.

 

And going further you can find that:

Note that in the service not all of the R packages are supported. See supported packages at the end of this article for the list of packages currently supported in the Power BI service.

And the link with a full list of supported packages in Power BI Service - https://docs.microsoft.com/en-us/power-bi/service-r-packages-support

 

Please go through both links and check whether you ran into the limits or not.

 

Regards,
Ruslan
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!

 

 

Hello again @zoloturu

 

After carefully re-reading those articles and doing some tests I believe there are 2 things that migh the source of my problem:

1) from the link "https://docs.microsoft.com/en-us/power-bi/service-r-packages-support "  ->"For security and privacy reasons, R packages that provide client-server queries over the World-Wide Web (such as RgoogleMaps) in the service, are not supported. Networking is blocked for such attempts. See the following section for a list of supported and unsupported R packages. "

However, the package that I use to connect to the DB is supported by Service. And the package was basically made to connect to databases, so it would be weird to support it but to not allow most of the stuff to work.

 

2) from the link "https://docs.microsoft.com/en-us/power-bi/visuals/service-r-visuals" -> "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."

This might be another problem but they don't explain what the consider as not required. My connection is required but maybe they don't think it is.

After testing for a bit I managed to put all my code, including dbconnection and fetching of the query, inside a barplot function. So i don't believe that much that this is the problem as it would be super weird that he would consider something as not required for the visual when it is inside the funcion that creates the visual

 

Overall, I still don't know if it is a code problem, database problem or power BI Service problem (like the limitations above)

 

Best regards,

Pedro Pereira

 

 

@Pedro-Pereira, following back on this older thread -- were you able to connect to MySQL with the online service?  I'm using dbConnect and it works fine in the desktop but i get the same message you received when refreshing in the online service -> "Unknown MySQL Server Host".

I will say i've had a lot of trial and error to get this far -- for only a few lines of code there are a lot of things that have to go right!

 

For the next person googling, here's what i am trying to do:

- at a daily PBi refresh, save a few summary datapoints from a table visual (basically a pivot table on manufacturing stages to summarize dollars, counts, average time, median time, maximum time in each stage).  
- read the table data and graph each day's summary data in a stacked graph to see trends as product moves thru stages

- figured since i've got a visual setup for the MySQL, go ahead and build a simple graph.  So my code is:

 
# Paste or type your script code here:
library (RMySQL)
library(data.table)
library(dplyr)
library(ggplot2)
names(dataset) <- c('date', 'stage', 'value', 'count', 'avgtime', 'maxtime', 'mediantime')
g <- ggplot(dataset, aes(x=stage, y=value, fill=count)) + geom_bar(position="dodge", stat="identity")
g
con <- dbConnect(MySQL(), user="XXXXXXX", password="YYYYYYY",
dbname="DDDDDDD", host="HOST URL in AWS",client.flag=CLIENT_MULTI_STATEMENTS)
# change PBI names to column names and write it back
names(dataset) <- c('date', 'stage', 'value', 'count', 'avgtime', 'maxtime', 'mediantime')
dbWriteTable(con,"MYSQL TABLE NAME",dataset,append=TRUE,row.names=FALSE)
dbDisconnect(con)

Hello @Pedro-Pereira,

 

Sometimes limitations are not listed in the description. It might be that they missed something. I had such experience when worked with Premium capacity and found weird not documented limits. I recommend you to go to the page https://powerbi.microsoft.com/en-us/support/ and create a support ticket using button downside. Then you will receive a help from MS support team. You can speed up this process mentioning this thread to a support engineer.

 

Regards,
Ruslan
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors