我想讓用戶界面從textarea交互式更改爲selectInput並再次返回。如何在shinyapp中以交互方式更改UI
這是我放在server.r。我使用counter1和counter2讓shinyapp知道選擇哪個動態UI。當按下提交按鈕時,會在計數器1或計數器2上加1。這樣counter1和counter2將交替相同或不相同。
library(shiny)
counter1 <- 1
counter2 <- 0
shinyServer(function(input, output) {
output$MainAction <- renderUI({
dynamicUi()
})
dynamicUi <- reactive({
if (counter11 == counter2){
counter1 <- counter1 + 1
return(
selectInput("choose","Choose yes or no", choices = c("yes"="yes","no"="no"))
)
}
else {
counter2 <- counter2 + 1
return(
tags$textarea(id="textfield", rows=8, cols=90, "put your text here")
)
}
})
})
而這就是我把ui.r
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("My shiny app"),
sidebarPanel(
uiOutput("MainAction"),
submitButton("action")
),
mainPanel(
tabsetPanel(
tabPanel("Output", uiOutput("outputaction"))
)
)
))
的結果是shinyapp枝與textarea的。顯然這不是我想要的。有沒有人知道這裏有什麼問題?我想我錯過了一些東西。
非常感謝提前!
謝謝喬!我現在開始工作了。我想我太專注於爲什麼我的'解決方案'不起作用。 – rdatasculptor