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

The Fabric community is upgrading! Read all of the details including the timeline and what you can expect. Learn more

Reply
jschne
Frequent Visitor

Custom Visual with R script can't return strings?

Hi,

 

I can't figure out what I'm doing wrong... No matter what I try, I can't get a custom visual to keep my data as strings, it always does some weird index conversion...

 

This is my (simply) script.R:

source('./r_files/flatten_HTML.r')

############### Library Declarations ###############
libraryRequireInstall("ggplot2");
libraryRequireInstall("plotly")
####################################################

################### Actual code ####################


fig <- plot_ly(
type = 'table',
cells = list(
values = rbind(Values$id, Values$string)
))


####################################################

############# Create and save widget ###############
p = ggplotly(fig);
internalSaveWidget(p, 'out.html');
####################################################

 

If I give it a table:

id,string

1,Test1

2,test

3,Test1

4,test

5,not test

 

I get a visual table:

1,3

2,2

3,3

4,2

5,1

 

This is driving me nuts and it's probably a really simple answer!

 

 

PS I used the defaults generated by:

pbiviz new no_strings -t rhtml

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @jschne ,

 

I assume you are facing the implicit string to factor conversion, this R: rbind string to factor column - Stack Overflow provides two approaches to tackle this challenge.

 

Hopefully, this provides what you are looking for.

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User
Super User

Hey @jschne ,

 

I assume you are facing the implicit string to factor conversion, this R: rbind string to factor column - Stack Overflow provides two approaches to tackle this challenge.

 

Hopefully, this provides what you are looking for.

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

You saved my Friday!

 

For some reason the code worked in RStudio, but it needed that stringsasFactors to work in the custom viz.

 

Thanks again!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.