rpowerbihtmlwidgets

Power BI: include an htmlwidget other than a plotly graphic


Following this amazing answer and this tutorial, I have been able to include an interactive ggplotly in Power BI:

enter image description here

I'm wondering whether it is possible to include other htmlwidgets. I tried with DT and rAmCharts4 but I got only an empty plot, without error notification. Would you have an example of another htmlwidget included in Power BI?


EDIT

I finally managed with DT. And with highcharter.

enter image description here

enter image description here


Solution

  • Since I know manage, I answer my own question. Here is an example. First, install pbiviz as explained in the links given in my question.


    source('./r_files/flatten_HTML.r')
    
    ############### Library Declarations ###############
    libraryRequireInstall("ggplot2");
    libraryRequireInstall("ggiraph")
    ####################################################
    
    ################### Actual code ####################
    data <- Values # we will use 'mtcars' as 'Values'
    data$carname <- row.names(data)
    gg_point <- ggplot(data = data) +
      geom_point_interactive(aes(x = wt, y = qsec, color = disp,
                                 tooltip = carname, data_id = carname)) + 
      theme_minimal()
    ####################################################
    
    ############# Create and save widget ###############
    p <- girafe(ggobj = gg_point)
    internalSaveWidget(p, 'out.html');
    ####################################################
    
    ################ Reduce paddings ###################
    ReadFullFileReplaceString('out.html', 'out.html', ',"padding":[0-9]*,', ',"padding":0,')
    ####################################################
    

    The data imported in Power BI corresponds to Values in the script.

    Since we want to use mtcars as data, we save it as an Excel file, but before that, we add a column with the row names, because we will use the row names as tooltips:

    mtcars$carname <- rownames(mtcars) openxlsx::write.xlsx(mtcars, "mtcars.xlsx")

    enter image description here