Rstudio shiny not able to use ggvis

后端 未结 1 1750
无人共我
无人共我 2020-12-16 07:08

I have an RStudio Shiny server running and I installed ggvis from https://github.com/rstudio/ggvis but I am not able to reproduce any of the demo examples in the server.

相关标签:
1条回答
  • 2020-12-16 07:50

    Source ggvis in your ui.R file (example here 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")]
      })
    })
    
    0 讨论(0)
提交回复
热议问题