【问题标题】:Using formattable and plotly simultaneously同时使用 formattable 和 plotly
【发布时间】:2017-01-12 03:58:06
【问题描述】:

如果同时使用 formattable 和 plotly,如果运行以下代码,则会给出错误“last_plot() 中的错误:最后一个图不存在”,这是 Nico Katze 在@的评论部分已经提到的问题987654321@。

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:: 将函数直接链接到包。但是,这会产生相同的错误,因此无法解决问题。有人有解决这个问题的办法吗?

【问题讨论】:

    标签: r datatable shiny plotly


    【解决方案1】:

    找到了答案!它实际上是使用 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)))
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-04
      • 2021-12-06
      • 1970-01-01
      相关资源
      最近更新 更多