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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. 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
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

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.

Top Solution Authors