4

Shiny で ggvis を使用しようとしましたが、テスト サンプルでエラーが発生しました。コードはこのメッセージの最後にあります。

光沢のある ggvis を実行しようとしたときにのみ、次のエラー メッセージが表示されました。

Guessing formula = mpg ~ wt
Error in rep(col, length.out = nrow(data)) : 
   attempt to replicate an object of type 'closure'

server.R の行をコメントアウトすると

layer_model_predictions(model = "lm") %>%

エラーメッセージは表示されず、線形フィッティングラインが得られないことを除いて、光沢のあるアプリは正常に動作します。コードの ggvis 部分も、shiny を使用しない場合は正常に動作します。光沢のあるリアクティブ データ セットと関係があると思いますが、簡単な修正方法を見つける手がかりがありません。

なにか提案を?

助けてくれてありがとう!

イン

ui.R

library(ggvis)
shinyUI(pageWithSidebar(

  div(),

  sidebarPanel(
    sliderInput("n", "Number of points", min = 1, max = nrow(mtcars),
                value = 10, step = 1)
  ),

  mainPanel(
    ggvisOutput("plot"),
    tableOutput("mtc_table")
  )

))

サーバー.R

library(shiny)
library(ggvis)
library(dplyr)

shinyServer(function(input, output, session) {

  mtc <- reactive({

            mtc <- mtcars[1:input$n, ]
            mutate(mtc, carname=rownames(mtc), id = 1:nrow(mtc))
  })


  all_values <- function(x) {

      if(is.null(x)) return(NULL)
      row <- mtc()[mtc()$id == x$id, ]
      row$carname

  }

  mtc %>%
         ggvis(x= ~wt, y= ~mpg, key := ~id, fill = ~factor(cyl)) %>%
         layer_points() %>%
         group_by(cyl) %>%
         add_tooltip(all_values,"hover") %>%
         layer_model_predictions(model = "lm") %>%
         bind_shiny("plot")

  output$mtc_table <- renderTable({
    mtc()[, c("carname", "wt", "mpg", "cyl")]
  })
})
4

0 に答える 0