renderPlotly function gives two errors when running via do.call()
まだ誰も着手していません。
- 主要言語
- R
- スター
- 2.7k
- フォーク
- 641
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
The renderPlotly function gives two errors when running it via do.call().
Thi first is that quoting done in renderPlotly doesn't seem to be accepted by the subsequent Shiny functions.
The second is because do.call adds another layer of frames the label = sys.call(-1)[[1]] in shiny::installExprFunction() does not correctly capture the function name for use as a label. This seems to be hardcoded in most shiny render functions such as renderPlot().
I think this is due to changes made in the shiny code to support quosures (https://github.com/rstudio/shiny/pull/3472). I don't have any experience with quoting and quosures but I put my current workaround at the end of the reprex.
library(plotly)
library(shiny)
a_plot <- plot_ly(x = 1:3, y = 2:4)
# Usual call of renderPlotly works
plot_redered <-renderPlotly(a_plot)
# Using do.call gives an error
plot_redered <-do.call(renderPlotly, list(expr = a_plot))
#> Error in exprToQuo(expr, env, quoted = TRUE): Don't know how to convert 'plotly' to a function; a quosure or quoted expression was expected
# Put the plot in a quosure gives a different error
q_plot <- rlang::quo(plot_ly(x = 1:3, y = 2:4))
plot_redered <-do.call(renderPlotly, list(expr = q_plot, quoted = T))
#> Error in as.character(label): cannot coerce type 'closure' to vector of type 'character'
# Modified function that manually specifies label = "renderPlotly" when calling shiny::installExprFunction and uses enquote() in place of substitute()
renderPlotly_w_label <- function (expr, env = parent.frame(), quoted = FALSE){
if (!quoted) {
quoted <- TRUE
expr <- enquote(expr)
}
shiny::installExprFunction(expr, "func", env, quoted, label = "renderPlotly")
expr2 <- quote(getFromNamespace("prepareWidget", "plotly")(func()))
renderFunc <- htmlwidgets::shinyRenderWidget(expr2, plotlyOutput, environment(),
quoted, cacheHint = list(label = "renderPlotly",
userExpr = expr))
shiny::snapshotPreprocessOutput(renderFunc, function(value) {
json <- from_JSON(value)
json$x <- json$x[setdiff(names(json$x), c("visdat",
"cur_data", "attrs"))]
to_JSON(json)
})
}
# This succeeds
plot_redered <-do.call(renderPlotly_w_label, list(expr = a_plot))
Created on 2022-02-17 by the reprex package (v2.0.1)
Standard output and standard error
[31mx[39m Install the [34mstyler[39m package in order to use `style = TRUE`.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
renderPlotly 関数から始めて、issue にある do.call() の例を再現し、その後 shiny::installExprFunction が quoting、quosures、labels をどのように扱うかを調べます。renderPlotly が do.call() 経由で報告されたどちらのエラーも発生せずに動作すれば完了です。issue では特定のソースファイルやテストは指定されていません。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- r
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100