同时使用 formattable 和 plotly [英] Using formattable and plotly simultaneously

查看:18
本文介绍了同时使用 formattable 和 plotly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If formattable and plotly are used simultaneously the error "Error in last_plot() : The last plot doesn't exist" is given if the following code is run which is a problem already mentioned by Nico Katze in the comment section of 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:: 将函数直接链接到包.但是,这会产生相同的错误,因此无法解决问题.有没有人有解决这个问题的办法?

The problem can be solved by detaching the plotly package but the problem is that I want to use both packages.Trying to find a solution I ended up on this page http://www.ats.ucla.edu/stat/r/faq/referencing_objects.htm. A proposed solution is linking the function directly to the package using formattable::. This however gives the same error so it doesn't resolve the problem. Does anyone have a solution for this problem?

推荐答案

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

Found the answer!It is actually using formattable:: but on the style function which seem to be the problem. Below the code that is working when both plotly and formattable are loaded.

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)))
)

这篇关于同时使用 formattable 和 plotly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆