考虑以下示例
ui.R:
library(shiny)
library(shinyjs)
shinyUI(
tabPanel("VIEW",
tabsetPanel(id="viewic",
tabPanel("view1",
fluidRow( column(2,
actionButton("button1", "BUTTON1")),
column(2,
actionButton("button2", "BUTTON2"))
))
tabPanel(" View2"))),
fluidRow(
uiOutput("ui1")
),
fluidRow(
uiOutput("ui2")
))
服务器:
library(shiny)
library(shinyjs)
shinyServer(function(input, output,session){
observeEvent(
input$button1,
output$ui1 <- renderUI({isolate({
column(3,
selectInput("selectview1",
label = "Select Id",
choices = c("1","2","3")
))})}))
observeEvent(
input$button2,
output$ui2 <- renderUI({isolate({
column(3,
selectInput("selectview2",
label = "Select Id",
choices = c("4","5","6")
))})}))
})
如何重置会话,即;当我按下button1时,会出现带有id selectview1的selectinput,当我按下按钮2时,会出现其中定义了id selectview2的selectInput,但是当点击button1时首先出现的selectinput也会随之显示,反之亦然。我试过重置和切换,但它没有正常工作。
答案 0 :(得分:0)
编辑:在selectInputs上使用conditionalPanel。所以有一些效果:
conditionalPanel(condition = 'input.button1 % 2 > 0',
uiOutput("ui1")
)
检查actionButton的值是否为偶数,只在奇数时显示。因此,假设按钮从0开始,它将在1,3,5,7 ......单击后显示。
我认为这应该有效。你能尝试一下吗?
如果您只想根据点击隐藏按钮,请查看conditionalPanel()并在该功能中包装您的按钮代码(ui侧)。
http://shiny.rstudio.com/reference/shiny/latest/conditionalPanel.html
答案 1 :(得分:0)
ui.R
库(有光泽)
库(shinyjs)
shinyUI(
fluidPage(
的TabPanel(&#34; VIEW&#34;,
tabsetPanel(id="viewic",
tabPanel("view1",
fluidRow(第2列,
actionButton("button1", "BUTTON1")),
柱(2,
actionButton("button2", "BUTTON2"))
)),
tabPanel(&#34; View2&#34;))),
fluidRow(
uiOutput("ui1")
),
fluidRow(
uiOutput("ui2")
)))
server.R
库(有光泽) 库(shinyjs)
shinyServer(函数(输入,输出,会话){
observeEvent(
input$button1,
output$ui1 <- renderUI({isolate({
output$ui2<-renderUI(
isolate({
dataTableOutput(NULL)
} ) )
column(3,
selectInput("selectview1",
label = "Select Id",
choices = c("1","2","3")
))})}))
observeEvent(
input$button2,
output$ui2 <- renderUI({isolate({
output$ui1<-renderUI(
isolate({
dataTableOutput(NULL)
} ) )
栏目(3,
selectInput("selectview2",
label = "Select Id",
choices = c("4","5","6")
))})}))
})
此代码有效。