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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

RHTML custom visual, data loss results in misleading plot

Hello,

 

has anyone encountered the problem where the visual looks significantly different than when compiled in R?

My output clearly missed out on alot of data, as many bars are missing from the column plot. Data consists of less than 2000 obs.

 

This is my R-code, if anyone are interested:

 

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

############### Library Declarations ###############
libraryRequireInstall("ggplot2");
libraryRequireInstall("plotly")
libraryRequireInstall("tidyverse")
libraryRequireInstall("scales")
libraryRequireInstall("lubridate")


################### Actual code ####################
# Prep maskin data --------------------------------------------------------
maskin = Values %>%
  mutate(Ferdig_Tid_Short = as.Date(Ferdig_Tid_Short),
         MaskinNr = as.character(MaskinNr)) %>% 
  mutate(
    year = year(Ferdig_Tid_Short),
    first = floor_date(x = today(),'year',),
    last = as.Date(ifelse(year(today())==year,
                          as.character(today()),
                          as.character((ceiling_date(x = today(),'year',)-days(1)))))
  ) %>%
  group_by(year,MaskinNr,MaskinGruppeNavn) %>% 
  summarise(
    maskintimer = sum(Reell_Maskintid),
    qyeartimer = as.numeric(max(last)-min(first))*24
  ) %>% 
  ungroup %>% 
  transmute(
    year = factor(year),
    MaskinNr = factor(MaskinNr, levels = unique(sort(as.numeric(Values$MaskinNr)))),
    maskingruppe = factor(MaskinGruppeNavn,
                          levels = c('65-90 tonn','120-400 tonn',
                                     '420-600 tonn',
                                     '1000-1500 tonn',
                                     'Pakningslegging')),
    diff = round(maskintimer/qyeartimer,3)
  );


# Lag plot ----------------------------------------------------------------
color_vec = c('#60D9BA','#287878','#01A001','#CFF06D','#00FF51','#FFFF00','#FF8000');


colors = maskin %>% 
  transmute(maskingruppe,
            MaskinNr = MaskinNr) %>%
  distinct() %>%
  arrange(MaskinNr) %>% 
  group_by(maskingruppe) %>% 
  mutate(color = map_chr(1:length(maskingruppe),function(x)color_vec[x])) %>% 
  pull(color);

g = maskin %>%
  filter(maskingruppe != 'Pakningslegging') %>% 
  ggplot(aes(year,diff,fill = MaskinNr)) +
  geom_col(position = position_dodge()) +
  facet_wrap(~maskingruppe) +
  theme_bw() +
  theme(plot.background = element_rect(fill = '#e7f0f0', color = '#e7f0f0'),
        legend.position="none") +
  xlab('') +
  ylab('') +
  scale_y_continuous (labels = scales::percent) +
  scale_fill_manual(values=colors);
####################################################

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

################ Reduce paddings ###################
ReadFullFileReplaceString('out.html', 'out.html', ',"padding":[0-9]*,', ',"padding":0,')
####################################################

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

This would definitively be a part of the problem, thanks for letting me know! Unfortuneately, it didn't fix the issue. For example, if i restrict the data (PBI filter) to a year with few observations, it is still wrong (even after updating top "count":30000). I'm assuming there is some R function that isn't supported in R?

View solution in original post

4 REPLIES 4
dm-p
Super User
Super User

Hi @Anonymous,

I don't do much with R, but with custom visuals in-general, they will cap at 1,000 data points by default unless the dataReductionAlgorithm is updated to declare your visual's data point limit (up to a maximum of 30,000).

If you haven't tried this, here's the relevant section of documentation that explains the default limit and how to configure your capabilities.json accordingly.

Hope this helps,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not applicable

This would definitively be a part of the problem, thanks for letting me know! Unfortuneately, it didn't fix the issue. For example, if i restrict the data (PBI filter) to a year with few observations, it is still wrong (even after updating top "count":30000). I'm assuming there is some R function that isn't supported in R?

Unfortunately R isn't really my wheelhouse, so I can't offer anything to help on that side of things; just that the capabilities are usually a common sticking point for data being limited in the visual's data view. Hopefully someone else may be able to clarify that part for you 🤞

All the best,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not applicable

Turned out that I forgot to select "sum machine hours" as an aggregation option in Power BI... (my fault). However, your proposal would still be a problem in the next step, thank you for making me aware of it! Power BI is way more fun when you can actually make your own visuals 🙂

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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