Reputation: 3
I set up 2 actionButton in my shiny app to insert user input into database and delete one record from DB.
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Phase1",
column(4,uiOutput("Phase1", inline = FALSE),
wellPanel(
actionButton("P1_Add", "Add",icon=icon("plus-circle")),
actionButton("P1_Del", "Del",icon=icon("minus-circle"))
)),
column(6,h1("Phase1 Input data is put here"),dataTableOutput("Phase1_Data"))
),
tabPanel("Phase2",uiOutput("Phase2",inline=FALSE)),
tabPanel("Phase3")
)
)
and i also defined a observe in server.R to response my click. but seems not working
obs_p1_add<-observe({
if(input$P1_Add)
{
cat("just click add button")
cat("test")
print (input$P1_Add)
output$Phase2<- renderUI({
list(h4("ha! change"))
})
}
})
any one can teach me where went wrong? thanks so much!
Upvotes: 0
Views: 1792
Reputation: 675
Your code works for me!
ui.R:
library(shiny)
shinyUI(fluidPage(
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Phase1",
column(4,uiOutput("Phase1", inline = FALSE),
wellPanel(
actionButton("P1_Add", "Add",icon=icon("plus-circle")),
actionButton("P1_Del", "Del",icon=icon("minus-circle"))
)),
column(6,h1("Phase1 Input data is put here"),dataTableOutput("Phase1_Data"))
),
tabPanel("Phase2",uiOutput("Phase2",inline=FALSE)),
tabPanel("Phase3")
)
)
))
server.R:
library(shiny)
shinyServer(function(input, output) {
obs_p1_add<-observe({
if(input$P1_Add)
{
cat("just click add button")
cat("test")
print (input$P1_Add)
output$Phase2<- renderUI({
list(h4("ha! change"))
})
}
})
})
Text renders in second tab after click:
Upvotes: 0