考虑以下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”的文本被默认呈现。如何在操作按钮还没有被按下时显示默认输入?
input$goButton>0
时,您才能将nText
设置为input$n
,否则显示50。 - Dean MacGregor