我正在建立一个闪亮的应用程序,我需要一个计数按钮,以添加与数字输入的互动。所以我想要一个数字输入,用户可以自由使用,但也有一个用户可以点击的按钮,数字输入加1(所以如果用户选择20,然后点击按钮,输入就变成了21)。我有两个单独的工作,但不能让交互工作。数字输入会使用add按钮进行更新,但是如果我使用add numeric输入更改了值,那么到目前为止的点击次数就会继续。这就是我现在所拥有的:
library(shiny)
# https://shiny.rstudio.com/reference/shiny/1.3.2/updateNumericInput.html
# https://gist.github.com/aagarw30/69feeeb7e813788a753b71ef8c0877eb
ui <- shinyUI(
fluidPage(
tags$b("Simple counter using reactiveValues() - An example"),
numericInput("inNumber", "Input number", 0),
actionButton("add1", "+ 1"),
plotOutput("plot")
)
)
server <- function(input, output, session) {
counter <- reactiveValues(countervalue = 0) # Defining & initializing the reactiveValues object
observeEvent(input$add1, {
counter$countervalue <- counter$countervalue + 1 # if the add button is clicked, increment the value by 1 and update it
})
observeEvent(input$add1, {
updateNumericInput(session, "inNumber", value = counter$countervalue )
})
output$plot <- renderPlot({
hist( rnorm(input$add1))
})
}
shinyApp(ui, server)发布于 2020-11-27 08:02:01
您必须引用histogramm中的数字输入:
library(shiny)
# https://shiny.rstudio.com/reference/shiny/1.3.2/updateNumericInput.html
# https://gist.github.com/aagarw30/69feeeb7e813788a753b71ef8c0877eb
ui <- shinyUI(
fluidPage(
tags$b("Simple counter using reactiveValues() - An example"),
numericInput("inNumber", "Input number", 0),
actionButton("add1", "+ 1"),
plotOutput("plot")
)
)
server <- function(input, output, session) {
counter <- reactiveValues(countervalue = 0) # Defining & initializing the reactiveValues object
observeEvent(input$add1, {
counter$countervalue <- input$inNumber + 1 # if the add button is clicked, increment the value by 1 and update it
updateNumericInput(session, "inNumber", value = counter$countervalue )
})
output$plot <- renderPlot({
hist( rnorm(input$inNumber))
})
}
shinyApp(ui, server)https://stackoverflow.com/questions/65030433
复制相似问题