【发布时间】:2013-12-08 11:34:30
【问题描述】:
我想让用户界面以交互方式从 textarea 变为 selectInput 并再次返回。
这是我放在 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 保持一致。显然这不是我想要的。有谁知道这里出了什么问题?我想我错过了什么。
非常感谢!
【问题讨论】: