【发布时间】:2016-02-13 05:19:36
【问题描述】:
考虑以下 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”的文本。
如果尚未按下操作按钮,如何让输出显示为默认输入?
【问题讨论】:
-
您可以将
nText设置为input$n仅当input$goButton>0否则显示50。