how to convert datatable into data frame for plot in ggplot2.

Hi, am beginner in R.Trying to solve this but ...
Error in :
cannot coerce class ‘c("datatables", "htmlwidget")’ to a data.frame

Hi @smriti_j, welcome to RStudio Community.

It's hard to offer you specific help by just looking at an error message. It would be ideal if you could provide a reproducible example (reprex). Please read this guide to see how to create one:

yes, generally speaking this is not done.
The data.table widget you have access to , you presumably have access to because you provided an actual dataframe to a DT::renderDT, so the programmer would use that data rather than try to re-extract the data from the widget representation.

One must wonder does @smriti_j have a particularly bizarre context that means this is not the case...?


you make a frame.
you send this to a renderDT to see a table on screen
you send this to a renderPlot to visualise a chart on screen


you make a frame,
you send this to a renderDT to see a table on screen
you try to take a renderDT and make a plot from it.... bad idea.

why not use the frame you made ?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

You can Plot with data.table , the problem ist something else.

1 Like

Thank you for reply me but it's not working in htmlwidget. Error is coherence class in r and I didn't understand why it's so...

Thank you for this help.
Actually problem is facing when I tried to convert htmlwidget data table into data frame. But it's not working I tried many conversion method and all stuff. And that htmlwidget dataframe is an output of function.

Sorry but those details don't really help us understand how to help you fix the problem. As Markus_Hauschel said, you can easily make ggplot2 visualizations with data.table objects, so you may not need to convert in the first place.

Is it possible for you to post a reprex of your issue?

1 Like

I think the data tables being referred to are library(DT) data tables rather than data.table objects, but a reprex would still be required.


But it's not plotted directly. Require data frame that's why I need to convert.