Html file saved by savewidget can not be recognised by browser

This is my code:
#####################################
library(plotly)
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
x<-plot_ly(d, x = ~carat, y = ~price, color = ~carat,
size = ~carat, text = ~paste("Clarity: ", clarity))
htmlwidgets::saveWidget(x, “x.html”)
######################################

x.html can not be open by browser. Please see attachment for this “broken” html’s content.

Please help! Thanks!

Different attemp; same failure:

Hey @vic,

This works for me (in numerous browsers):

p <- plot_ly(z = ~volcano) %>% add_surface()
htmlwidgets::saveWidget(p, file = "testing.html")

with plotly_4.5.6.900 and htmlwidgets_0.8

I found out that If I do not use Rstudio, it works. I just switch to RGui. In RGui, the plot will pop up with weird url like “file:///C:/Users/Administrator/AppData/Local/Temp/RtmpEjbViP/viewhtml12383ee75cbb/index.html”.

Thank you.

I also keep getting this error even after I updated R, Rstudio, Plotly, and htmlwidgets to the latest version:

Error in htmlwidgets::saveWidget(p, “fuckyouuu.html”) :
Saving a widget with selfcontained = TRUE requires pandoc. For details see:

With due respect, your answer did not really answer anything.

I understand there is no freen lunch so I just give up this approach and go back to use Matlab

Thank you anyway.