首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反应元件和ggvis

反应元件和ggvis
EN

Stack Overflow用户
提问于 2015-01-16 03:36:03
回答 1查看 187关注 0票数 1

我有一个问题,以获得一个ggvis图形显示使用反应元素。下面是我得到的错误:.getReactiveEnvironment()$currentContext()Operation not allowed without an active reactive context.中的错误(您试图做一些只能在反应表达式或观察者中完成的事情)。

我看了其他帖子,所以我想我需要在某个地方使用“观察”({}),但我不知道在哪里。我试过了

observe({ df <- CreateDF(input$PMNT, input$Periods, input$Rate) )}

当我这样做时,图形会显示,但当我更改输入值时,图形不会更新。

感谢您所能提供的洞察力。

以下是相关代码:

服务器。R:

代码语言:javascript
复制
library(ggvis)
library(dplyr)
source("functions.R")

shinyServer(function(input, output) {

  input_PMNT <- reactive(input$PMNT)
  input_Periods <- reactive(input$Periods)
  input_Rate <- reactive(input$Rate)

observe(
df <- CreateDF(input$PMNT, input$Periods, input$Rate)
)
df %>% ggvis(x = ~time, y = ~pv) %>% layer_bars(width=1, fill := "#fff8dc") %>%
  add_axis("x", title = "Period") %>%
  add_axis("y", title = "Value") %>% 
  bind_shiny("AnPlot", "AnPlot_ui")

})

ui.R:

代码语言:javascript
复制
library(shiny)
library(ggvis)
library(dplyr)

shinyUI(fluidPage(

  titlePanel("Annuity Calculator"),

  sidebarLayout(
    sidebarPanel(
       radioButtons("AnType", 
                    "Annuity Type:",
                    list("Level", "Geometric", "Arithmetic"),
                    selected="Level")
    ),
    mainPanel(
      numericInput("PMNT", "Enter the regular payment:", min=0, value=100),
      numericInput("Periods", "Enter the number of periods:", min=0, value=10),
      numericInput("Rate", "Enter the interest rate, as a decimal:", value=0.07),
      ggvisOutput("AnPlot"),
      uiOutput("AnPlot_ui")

    )
  )
))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-16 04:48:43

observe({ df <- CreateDF(input$PMNT, input$Periods, input$Rate) )}这个表达式对我来说没有多大意义,因为df只在观察者中可见,并且观察者不返回任何东西。相反,您可以尝试df <- reactive( CreateDF(input$PMNT, input$Periods, input$Rate) )

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27976932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档