Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few questions regarding ModeBar functions #38

Open
Tomer-Tsaban opened this issue Dec 4, 2018 · 10 comments
Open

A few questions regarding ModeBar functions #38

Tomer-Tsaban opened this issue Dec 4, 2018 · 10 comments

Comments

@Tomer-Tsaban
Copy link

Tomer-Tsaban commented Dec 4, 2018

Hi Alicia,
I recently came across iheatmapr package and it is great! very useful and straight forward.

however, I have some questions regarding the functionality of the ModeBar (the bar of plotly designed options, of snapshot, zoom etc).

  1. is there a way to modify which options are being presented to the user? for example if I wouldn't like to allow the png download. I know there is a similar option in plotly, by config, e.g. as shown here
    https://stackoverflow.com/questions/37437808/how-to-custom-or-display-modebar-in-plotly

this doesn't seem to work when I try it in iheatmap r, e.g. like this -

q<-main_heatmap(als_genes_cor)%>%
        add_row_dendro(als_ord_hclust_genes) %>%
        add_col_dendro(als_ord_hclust_genes) %>%
        add_row_labels(side=c("right")) %>%
        add_col_labels() %>%
        config(displaylogo = FALSE,
               modeBarButtonsToRemove = list(
                       'sendDataToCloud',
                       'toImage',
                       'autoScale2d',
                       'resetScale2d',
                       'hoverClosestCartesian',
                       'hoverCompareCartesian'
               ))
        
q

I get this error
Error in config(., displaylogo = FALSE, modeBarButtonsToRemove = list("sendDataToCloud", : could not find function "config"

  1. is there a way to control the output of those options? specifically, I would like to change the size of the plot being downloaded to be larger than the default one.

Thanks alot!

@AliciaSchep
Copy link
Contributor

Hi @Tomer-Tsaban this is not currently readily configurable with iheatmapr, unfortunately. However, there is a hacky back-door approach you can use to get this effect:

# q is the heatmap object created above
# first convert it to an htmlwidgets object proper (this is normally done during the print process)
q_widget <- to_widget(q)
# Edit the htmlwidget object itself
q_widget$x$config$modeBarButtonsToRemove <- list(
'sendDataToCloud',
'toImage',
'autoScale2d',
'resetScale2d',
'hoverClosestCartesian',
'hoverCompareCartesian'
)
# you should be able to display the heatmap using q_widget similarly to how you would q.  

Having a modify_config function to enable this customization directly seems like a good feature to add though going forward.

@AliciaSchep
Copy link
Contributor

Re the 2nd question -- I don't know. I am not aware of a way to do that.

@Tomer-Tsaban
Copy link
Author

Hi Alicia, thanks for your answer!

I tried to implement what you suggested (exactly your code) and for some reason I get this error:
ERROR: unable to find an inherited method for function ‘to_widget’ for signature ‘"iheatmapr"

are you familiar with this?

@AliciaSchep
Copy link
Contributor

Try iheatmapr::to_widget -- maybe another package is loaded that also has to_widget method that is shadowing iheatmapr's.

@Tomer-Tsaban
Copy link
Author

Tomer-Tsaban commented Dec 15, 2018

Hi, thanks for your quick responses!

I tried again and figured out that the problem is with shiny package.
I use iheatmapr in a shiny app, and this is how the error was received. sorry for foolishly not stating that out previously.

anyhow, when trying the to_widget function in a non-shiny context, it works smoothly.
however when trying to embed in shiny, this error comes up again. here's a simple reproducible example with the measles data:
`
data(measles, package = "iheatmapr")

ui<-fluidPage(
iheatmaprOutput("output_q_widget")
)

server<-function(session,input,output){

    q<-main_heatmap(measles, name = "Measles<br>Cases", x_categorical = FALSE,
                    layout = list(font = list(size = 8))) %>%
            add_col_groups(ifelse(1930:2001 < 1961,"No","Yes"),
                           side = "bottom", name = "Vaccine<br>Introduced?",
                           title = "Vaccine?",
                           colors = c("lightgray","blue")) %>%
            add_col_labels(ticktext = seq(1930,2000,10),font = list(size = 8)) %>%
            add_row_labels(size = 0.3,font = list(size = 6)) %>%
            add_col_summary(layout = list(title = "Average<br>across<br>states"),
                            yname = "summary")  %>%
            add_col_title("Measles Cases from 1930 to 2001", side= "top") %>%
            add_row_summary(groups = TRUE,
                            type = "bar",
                            layout = list(title = "Average<br>per<br>year",
                                          font = list(size = 8)))
    
    q_widget <- to_widget(q)
    # Edit the htmlwidget object itself
    q_widget$x$config$modeBarButtonsToRemove <- list(
            'sendDataToCloud',
            'toImage',
            'autoScale2d',
            'resetScale2d',
            'hoverClosestCartesian',
            'hoverCompareCartesian'
    )
    #q_widget
    
    output$output_q_widget<-renderIheatmap({
            q_widget
            
    })

}

shinyApp(ui,server)
`
Thanks, and again sorry for lacking this information in my previous question.
EDIT: also, for some reason github won't accept the whole code snippet as code-text... sorry.

@AliciaSchep
Copy link
Contributor

Thanks for additional details... the issue is that renderIheatmap will call 'to_widget' but with the above approach that has already been done. As another temporary workaround, you could define

renderIheatmap2 <- function(expr, env = parent.frame(), quoted = FALSE) {
  if (!quoted) { expr <- substitute(expr) } # force quoted
  htmlwidgets::shinyRenderWidget(expr, iheatmaprOutput, env, quoted = TRUE)
}

and use that instead of renderIheatmap (basically an edit of that function that removes the call to 'to_widget')

Will be much better to add ability to edit config directly to the package, but in meantime hope that unblocks whatever app you are working on.

@Tomer-Tsaban
Copy link
Author

This works beautifully!
thanks alot

@rfenouil
Copy link

@AliciaSchep May I had a question to your suggestion ?

I succesfully removed logo using the strategy you suggested:

heatmapPlot_widget <- iheatmapr::to_widget(heatmapPlot);

heatmapPlot_widget[["x"]][["config"]][["displaylogo"]] = FALSE;
heatmapPlot_widget[["x"]][["config"]][["toImageButtonOptions"]] = list( format='svg');

But the 'svg' output does not seem to work.
Is the plotly version embedded in iHeatmapr too old to include this option ?

Thank you.

@daattali
Copy link

daattali commented Mar 9, 2021

Another vote for allowing a custom config.

This issue is currently unresolvable (even with the hacky way) in shiny apps because of #71 which was mentioned by @Tomer-Tsaban

@liangyu02
Copy link

NiuBi!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants