我試圖構建一個閃亮的應用程序。在我的代碼,我使用條件面板以下,其中用戶不同input.pkmodel
之間進行選擇,並根據不同的參數設置出現在用戶面前conditionalPanel在更改條件時不更新
library("shiny")
ui <- fluidPage(theme = shinytheme("united"),
actionButton("go", "RUN"),
selectInput("PKmodel",
"Select the PK Model:",
choices = list(" 1 Compartment Model" = 1,
" 2 Compartment Model" = 2),
selected = 1),
conditionalPanel(
condition = "input.PKmodel == 1",
numericInput("CL", "CL:", 5, min = 0.000001, max = 10000,step = .01)
),
conditionalPanel(
condition = "input.PKmodel == 2",
numericInput("CL", "CL:", 20, min = 0.000001, max = 10000,step = .01),
numericInput("VC", "V:", 13, min = 0.0000001, max = 20,step = .01))
)
server <- function(input, output) {
sim.data <- eventReactive(input$go,{
selectPKmod <- input$PKmodel
if (selectPKmod == 1) {
CLIN<-input$CL }
if (selectPKmod == 2) {
CLIN<-input$CL
VCIN<- input$VC }
})
}
shinyApp(ui = ui, server = server)
我面對這個問題: 當我選擇input.PKmodel == 2,CL參數值不會更改爲20「input.PKmodel == 2的默認值」,也不會更改爲任何用戶定義的值。但是,它保持CLIN = 5「input.PKmodel == 1的默認值」。
換句話說,如果我選擇input.PKmodel == 2,然後使用用戶界面更改了VCIN或CLIN的值,但這些值都不會改變。 對於CLIN,它保持固定爲5的值(來自默認值input.PKmodel == 1), 並且VCIN參數固定爲值13(來自input.PKmodel == 2)。所以看起來參數獲得了它們第一次出現的值,但是它們沒有被更新。 你能幫忙解決這個問題嗎?另外,請注意,我正在使用actionButton和eventReactive(我不確定這是否與問題有關係)。 感謝
非常感謝您!我改變了代碼,以確保沒有兩個輸入具有相同的ID,它的工作。 –