【发布时间】:2023-03-15 21:21:01
【问题描述】:
我闪亮的应用程序不起作用,我不知道为什么: 这会尝试获取输入并计算输出并渲染结果 在输出 $mortgagepayment。 当我运行应用程序时,它会给我以下消息:
.getReactiveEnvironment()$currentContext() 中的错误: 如果没有活动的反应上下文,则不允许操作。 (你试图做一些只能在反应式表达式或观察者内部完成的事情。)
library(shiny)
# Define UI ----
ui <- fluidPage(
titlePanel("Basic widgets"),
fluidRow(
# column(3,
# h3("Buttons"),
# actionButton("action", "Action"),
# br(),
# br(),
# submitButton("Submit")),
# column(3,
# h3("Single checkbox"),
# checkboxInput("checkbox", "Choice A", value = TRUE)),
column(3,
checkboxGroupInput("Fixed",
h3("Mortgage Year"),
choices = list("30 year" = 30,
"15 year" = 15,
"10 year" = 10),
selected = 1)),
# column(3,
# dateInput("date",
# h3("Date input"),
# value = "2014-01-01"))
),
fluidRow(
# column(3,
# dateRangeInput("dates", h3("Date range"))),
#
# column(3,
# fileInput("file", h3("File input"))),
column(3,
numericInput("housePrice",
h3("Housing Price"),
value = 1)),
column(3,
numericInput("percentageDown",
h3("Percentage Down"),
value = 1),min=0,max=1) ,
column(3, numericInput("mortgageYield", h3("Mortgage Yield"), value=0.0, min = 0, max = 0.1, step = NA,
width = NULL)),
),
fluidRow(
column(3, h3("Mortgage Payment"), verbatimTextOutput("mortgagepayment")))
)
# Define server logic ----
server <- function(input, output) {
housePrice = input$housePrice
downPayment = input$percentageDown
mortgageYield = input$mortgageYield
mortgageAmount = housePrice*(1-downPayment)
years = session$fixed
mortgagePayment = (mortgageAmount*mortgageYield)/(1-1/(1+mortgageYield)^(12*years))
output$mortgagepayment <-renderText({mortgagePayment})
}
# Run the app ----
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r shiny rendering shinyapps