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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Creating a Power BI Custom Visual R HTML internalSaveWidget(p, 'out.html') fviz_pca_var

Hi all, 

I would like to create a visual of a Principal Component Analysis using this fviz_pca_var function from this library factoextra.

 

I thought that p here internalSaveWidget(p, 'out.html') could be the output of fviz_pca_var function, but it is not working.

 

I getting this error:

Error Message:
R script error.
Loading required package: XML
Loading required package: htmlwidgets
Loading required package: dplyr

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

filter, lag

The following objects are masked from 'package:base':

intersect, setdiff, setequal, union

Loading required package: ggplot2
Loading required package: FactoMineR
Loading required package: factoextra
Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
Error in .getNamespace(pkg) :
invalid type/length (symbol/0) in vector allocation
Calls: internalSaveWidget ... file.exists -> system.file -> devtools_loaded -> .getNamespace
Execution halted

 

This is my script.r:

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

############### Library Declarations ###############
libraryRequireInstall("dplyr");
libraryRequireInstall("XML");
libraryRequireInstall("htmlwidgets");
libraryRequireInstall("ggplot2");
libraryRequireInstall("FactoMineR")
libraryRequireInstall("factoextra")

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

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

dataset <- Values[, 2:ncol(Values)];

dataset  <- dataset [,sapply(dataset , is.numeric)];

res.pca = PCA(datasetgraph = FALSE);

var = get_pca_var(res.pca);

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

############# Create and save widget ###############
p = fviz_pca_var(res.pcacol.var = "cos2",
              gradient.cols = c("#00AFBB""#E7B800""#FC4E07"), 
              repel = TRUE # Avoid text overlapping
              );

internalSaveWidget(p'out.html');
####################################################

 

Thank you so much for your help! 🙂

 

1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

Try to refer to the link, which inclueds the same error.

Change sizing policy of a widget in R and save it 

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

Try to refer to the link, which inclueds the same error.

Change sizing policy of a widget in R and save it 

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.