在Rstudio中,我可以';t将饼图保存为plotly生成的html
我在R中使用plotly来构造交互式图形。。。 但是我在rstudio中导出为html时遇到了问题(在我的pc中-在其他一些pc中没有问题) 例如,当我做这样的事情时在Rstudio中,我可以';t将饼图保存为plotly生成的html,r,character-encoding,rstudio,pandoc,plotly,R,Character Encoding,Rstudio,Pandoc,Plotly,我在R中使用plotly来构造交互式图形。。。 但是我在rstudio中导出为html时遇到了问题(在我的pc中-在其他一些pc中没有问题) 例如,当我做这样的事情时 id<- rep(1:10) df<- as.data.frame(id) df$response<- c(rep("sim", 3), rep("nao", 2), rep("sim", 1), rep("sim", 4)) tab<- as.data.frame(freq(df$response))
id<- rep(1:10)
df<- as.data.frame(id)
df$response<- c(rep("sim", 3), rep("nao", 2), rep("sim", 1), rep("sim", 4))
tab<- as.data.frame(freq(df$response))
tab<- tab[-3,]
library(plotly)
plot_ly(tab, labels = row.names(tab), values = Percentual, type = "pie") %>%
layout(title = enc2utf8("Sim/Nao response") )
我使用的是windows 7和Rstudio版本0.99.447–©2009-2015我认为您需要确保字符串采用UTF-8编码。试试这个
编码(df$response),它不起作用。我编辑了一些有关编码的结果…请尝试htmlwidgets::saveWidget?saveWidget(as.widget(p),file=“m2.html”)pandoc.exe:无法解码字节“\xf3”:Data.Text.Internal.Encoding.Fusion.streamUtf8:无效的UTF-8流错误:pandoc文档转换失败,错误为1另外:警告消息:正在运行命令'“C:/Program Files/RStudio/bin/pandoc/pandoc”+RTS-K512m-RTS C:\pnadc216\m2.html——从markdown\u strict——输出C:\pnadc216\m2.html——自包含——模板C:\Users\miguel.orrillo\AppData\Local\Temp\RtmpwDZlyv\file46705397168d.html”的状态为1
df$response<- c(rep("sim", 3), rep("não", 2), rep("sim", 1), rep("sim", 4))
Encoding(df$response)
[1] "unknown" "unknown" "unknown" "latin1" "latin1" "unknown" "unknown" "unknown"
[9] "unknown" "unknown"
all(stri_enc_isutf8(df$response))
> F
df$response <- stri_encode(df$response, "", "UTF-8")
all(stri_enc_isutf8(df$response))
> T
Encoding(df$response)
[1] "unknown" "unknown" "unknown" "UTF-8" "UTF-8" "unknown" "unknown" "unknown"
[9] "unknown" "unknown"
....
tab<- as.data.frame(freq(df$response))
tab<- tab[-3,]
plot_ly(tab, labels = row.names(tab), values = Percentual, type = "pie") %>%
layout(title = enc2utf8("Sim/Não response") )
pandoc.exe: Cannot decode byte '\xe3':Data.Text.Internal.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream
Error: pandoc document conversion failed with error 1
In addition: Warning message:
running command
'"C:/Program Files/RStudio/bin/pandoc/pandoc"
"C:\Users\miguel.orrillo\AppData\Local\Temp\RtmpqCrv6d\viewhtml32f478a42aff\inde x.html" --from markdown_strict --output "C:\testes\teste2.html" --self-contained --template "C:\Users\miguel.orrillo\AppData\Local\Temp\RtmpqCrv6d\file32f45bef54ef.html"' had status 1