gpt4 book ai didi

r - 同时使用 formattable 和 plotly

转载 作者:行者123 更新时间:2023-12-04 01:51:48 25 4
gpt4 key购买 nike

如果同时使用 formattable 和 plotly,则运行以下代码时会出现错误“last_plot() 中的错误:最后一个图不存在”,这是 Nico Katze 在 http://www.magesblog.com/2016/01/formatting-table-output-in-r.html 的评论部分中已经提到的问题.

library(formattable)
library(plotly)
DF <- data.frame(Ticker=c("", "", "", "IBM", "AAPL", "MSFT"),
Name=c("Dow Jones", "S&P 500", "Technology",
"IBM", "Apple", "Microsoft"),
Value=accounting(c(15988.08, 1880.33, NA,
130.00, 97.05, 50.99)),
Change=percent(c(-0.0239, -0.0216, 0.021,
-0.0219, -0.0248, -0.0399)))



formattable(DF, list(
Name=formatter(
"span",
style = x ~ ifelse(x == "Technology",
style(font.weight = "bold"), NA)),
Value = color_tile("white", "orange"),
Change = formatter(
"span",
style = x ~ style(color = ifelse(x < 0 , "red", "green")),
x ~ icontext(ifelse(x < 0, "arrow-down", "arrow-up"), x)))
)`

问题可以通过分离 plotly 包来解决,但问题是我想使用这两个包。试图找到一个解决方案,我最终在这个页面 http://www.ats.ucla.edu/stat/r/faq/referencing_objects.htm 上找到了。一个建议的解决方案是使用 formattable::将函数直接链接到包。但是,这会产生相同的错误,因此无法解决问题。有人能解决这个问题吗?

最佳答案

找到答案了!它实际上是使用 formattable::但在样式功能上似乎是问题所在。在加载 plotly 和 formattable 时工作的代码下方。

library(formattable)
library(plotly)
DF <- data.frame(Ticker=c("", "", "", "IBM", "AAPL", "MSFT"),
Name=c("Dow Jones", "S&P 500", "Technology",
"IBM", "Apple", "Microsoft"),
Value=accounting(c(15988.08, 1880.33, NA,
130.00, 97.05, 50.99)),
Change=percent(c(-0.0239, -0.0216, 0.021,
-0.0219, -0.0248, -0.0399)))
DF

formattable(DF, list(
Name=formatter(
"span",
style = x ~ ifelse(x == "Technology",
formattable::style(font.weight = "bold"), NA)),
Value = color_tile("white", "orange"),
Change = formatter(
"span",
style = x ~ formattable::style(color = ifelse(x < 0 , "red", "green")),
x ~ icontext(ifelse(x < 0, "arrow-down", "arrow-up"), x)))
)

关于r - 同时使用 formattable 和 plotly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39319427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com