簡體   English   中英

Rstudio閃亮不能使用ggvis

[英]Rstudio shiny not able to use ggvis

我運行了一個RStudio Shiny服務器,我從https://github.com/rstudio/ggvis安裝了ggvis,但我無法重現服務器中的任何演示示例。

當我使用服務器(3.1.0)中安裝的相同版本運行R時,我可以執行以下操作:

> library("shiny")
> library("ggvis")
The ggvis API is currently rapidly evolving. We strongly recommend that you do not rely on this for production, but feel free to explore. If you encounter a clear bug, please file a minimal reproducible example at https://github.com/rstudio/ggvis/issues. For questions and other discussion, please use https://groups.google.com/group/ggvis.

Attaching package: "ggvis"

The following object is masked from "package:stats":

    filter

> ggvis::ggvisOutput
function (plot_id = rand_id("plot_id")) 
{
    ggvisOutputElements(plot_id, spec = NULL, shiny = TRUE)
}
<environment: namespace:ggvis>

但是,當我在其中一個演示文件夾中嘗試示例時:

# ui.R
shinyUI(pageWithSidebar(
  div(),
  sidebarPanel(
    sliderInput("n", "Number of points", min = 1, max = nrow(mtcars),
                value = 10, step = 1),
    uiOutput("plot_ui")
  ),
  mainPanel(
    ggvisOutput("plot"),
    tableOutput("mtc_table")
  )
))

# server.R   
library("ggvis", lib.loc="/opt/R/R-3.1.0/lib64/R/library")))

shinyServer(function(input, output, session) {
  # A reactive subset of mtcars
  mtc <- reactive({ mtcars[1:input$n, ] })

  # A simple visualisation. In shiny apps, need to register observers
  # and tell shiny where to put the controls
  mtc %>%
    ggvis(~wt, ~mpg) %>%
    layer_points() %>%
    bind_shiny("plot", "plot_ui")

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

我明白了:

ERROR: could not find function "ggvisOutput"

使用ggvisOutput語句注釋掉該行然后正常呈現頁面但沒有繪圖。

有任何想法嗎?

你的ui.R文件中的源ggvis (例如http://128.199.255.233:3838/userApps/john/ggvistest/ ):

ui.R

library("ggvis")
shinyUI(pageWithSidebar(
  div(),
  sidebarPanel(
    sliderInput("n", "Number of points", min = 1, max = nrow(mtcars),
                value = 10, step = 1),
    uiOutput("plot_ui")
  ),
  mainPanel(
    ggvisOutput("plot"),
    tableOutput("mtc_table")
  )
))

server.R

library(shiny)
library(ggvis)
shinyServer(function(input, output, session) {
  # A reactive subset of mtcars
  mtc <- reactive({ mtcars[1:input$n, ] })

  # A simple visualisation. In shiny apps, need to register observers
  # and tell shiny where to put the controls
  mtc %>%
    ggvis(~wt, ~mpg) %>%
    layer_points() %>%
    bind_shiny("plot", "plot_ui")

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM