考慮以下actionButton演示: http://shiny.rstudio.com/gallery/actionbutton-demo.html閃亮:如何使無功值和默認值初始化
server.R:
shinyServer(function(input, output) {
# builds a reactive expression that only invalidates
# when the value of input$goButton becomes out of date
# (i.e., when the button is pressed)
ntext <- eventReactive(input$goButton, {
input$n
})
output$nText <- renderText({
ntext()
})
})
ui.R:
shinyUI(pageWithSidebar(
headerPanel("actionButton test"),
sidebarPanel(
numericInput("n", "N:", min = 0, max = 100, value = 50),
br(),
actionButton("goButton", "Go!"),
p("Click the button to update the value displayed in the main panel.")
),
mainPanel(
verbatimTextOutput("nText")
)
))
在這個例子中,在按下動作按鈕之前,右邊手邊的面板是空的。相反,我會默認呈現默認值爲「50」的文本。
如何獲取輸出以默認輸入顯示如果動作按鈕尚未按下?
只有在輸入$ goButton> 0時,才能將'nText'設置爲'input $ n',否則顯示50。 –