createAlert
的部分不起作用。谁能帮我修复它?任何帮助,不胜感激。
library(shiny)
library(shinyBS)
shinyUI(fluidPage(
titlePanel("Ouais...Ouais..."),
sidebarLayout(
sidebarPanel(
helpText("A new learner"),
selectInput("var",
label = "Choose a variable to display",
choices = c("begin", "win", "again", "give up"),
selected = "begin"),
radioButtons(
"filtre",
label = h5("Do you like me ?"),
choices = list("Yes" = 1, "No" = 0, "Get out" = 2),
selected = 1),
actionButton("initia", label = img(src="imgR.png", height = 200, width = 170) )
),
mainPanel(
**bsAlert("alert1"),**
textOutput("text1"),
textOutput("text2")
)
)
))
library(shiny)
library(shinyBS)
shinyServer(function(input, output, session) {
output$text1 <- renderText({
paste("You have selected", input$var)
})
output$text2 <- renderText({
paste("Do you want to go ? ", input$filtre)
})
**output$textalert <- renderText({
popupvar <- input$var
if(popupvar == "give up") {
createAlert(session, "alert1", "exampleAlert", title = "Oops",
content = "Go on, you'll win", append = FALSE)
} else if(popupvar == "begin") {
createAlert(session, "alert1", "exampleAlert", title = "Oops",
content = "Bravo.", append = FALSE)
} else {
closeAlert(session, "exampleAlert")
return("Greateful")
}
})**
observe({
input$initia
updateSelectInput(session, "var", selected = "begin")
updateRadioButtons(session, "filtre", selected = 1 )
})
})
您可以使用
observeEvent
来实现这一点。看看下面修改后的代码:
library(shiny)
library(shinyBS)
ui <- shinyUI(fluidPage(
titlePanel("Ouais...Ouais..."),
sidebarLayout(
sidebarPanel(
helpText("A new learner"),
selectInput("var",
label = "Choose a variable to display",
choices = c("begin", "win", "again", "give up"),
selected = "begin"),
radioButtons(
"filtre",
label = h5("Do you like me ?"),
choices = list("Yes" = 1, "No" = 0, "Get out" = 2),
selected = 1),
actionButton("initia", label = img(src="imgR.png", height = 200, width = 170) )
),
mainPanel(
bsAlert("alert1"),
textOutput("text1"),
textOutput("text2")
)
)
))
server <- shinyServer(function(input, output, session) {
output$text1 <- renderText({
paste("You have selected", input$var)
})
output$text2 <- renderText({
paste("Do you want to go ? ", input$filtre)
})
observeEvent(input$var,{
popupvar <- input$var
if(popupvar == "give up") {
createAlert(session, "alert1", "exampleAlert", title = "Oops",
content = "Go on, you'll win", append = FALSE)
} else if(popupvar == "begin") {
createAlert(session, "alert1", "exampleAlert", title = "Oops",
content = "Bravo.", append = FALSE)
} else {
closeAlert(session, "exampleAlert")
return("Greateful")
}
})
observe({
input$initia
updateSelectInput(session, "var", selected = "begin")
updateRadioButtons(session, "filtre", selected = 1 )
})
})
shinyApp(ui,server)
希望对您有所帮助!