2017-06-04 127 views
1

嘗試獲取數字輸入並在輸入上應用2個公式,並使用它們繪製直方圖。錯誤 - 參數「inputId」丟失,沒有默認值

UI端

library(shiny) 

shinyUI(fluidPage(
    actionButton (InputId = "USD", label = "US Bond Return"), 
    actionButton (InputId = "INR", label = "Indian Bond Return"), 
    numericInput(InputId = "num", label = "USD given by Investor", value = 0, 
min = 1, max = 1000, step = NA, width = NULL), plotOutput("hist"))) 

服務器端

library(shiny) 

shinyServer(function(input, output) { 

rv = reactiveValues(data = input$num) 
observeEvent(input$USD, { rv$data <- (input$num * 0.0225) }) 
observeEvent(input$INR, { rv$data <- (input$num*0.1) }) 

output$curve <- renderPlot({ 
hist(rv$data) 
}) 
} 
) 

回答

0

。在你的UI中的問題。它不是InputId,它的inputId(注意小i)。

因此,你的UI代碼將如下:

shinyUI(fluidPage(
    actionButton (inputId = "USD", label = "US Bond Return"), 
    actionButton (inputId = "INR", label = "Indian Bond Return"), 
    numericInput(inputId = "num", label = "USD given by Investor", value = 0, 
       min = 1, max = 1000, step = NA, width = NULL), plotOutput("hist"))) 
+0

謝謝!該錯誤現在已經解決,但現在它正在拋出其他錯誤: - .getReactiveEnvironment()中的錯誤$ currentContext(): 沒有活動的反應上下文不允許操作。 (你試圖做一些只能從被動表達式或觀察者內部完成的事情。) –

+0

這個錯誤是因爲'rv = reactiveValues(data = input $ num)'。你爲什麼不嘗試'rv = reactiveValues(data = input $ num)'。 – SBista

+0

另外,你試圖實現的東西不能從你的代碼中實現,因爲當你點擊你在應用程序的初始運行之後執行的按鈕時會調用observeEvent。你的'renderPlot(hist(rv $ data)})'在應用程序的初始運行過程中運行,永遠不會再被調用。考慮引用[this](https://shiny.rstudio.com/reference/shiny/latest/plotOutput.html)以瞭解閃亮應用的工作原理。另外,[Shiny App Tutorial](https://shiny.rstudio.com/tutorial/)是您學習的好地方。 – SBista

相關問題