1
我有一个shinyapp,其中主对象应根据更改更新其他对象/输入(执行其他操作的按钮,其结果不容易跟踪,例如,在线数据)。这就是为什么我不得不使用按钮的输入。有没有办法更新主对象,而无需重新编写每个按钮的代码?在我的例子,我不得不用observeEvent两次:对多个输入(按钮)有光泽的对象反应
library(datasets)
library(shiny)
ui<-fluidPage(
titlePanel("Telephones by region"),
sidebarLayout(
sidebarPanel(
selectInput("region", "Region:",
choices=colnames(WorldPhones)),
helpText("Data from AT&T (1961) The World's Telephones."),
actionButton("submit",
label = "submit"), # this also has other functions
actionButton("change",
label = "change") # this also has other functions
),
mainPanel(
plotOutput("phonePlot")
)
)
)
server<-function(input, output) {
data<-reactiveValues()
observeEvent(input$submit,{
data$data<-WorldPhones[,input$region]
})
observeEvent(input$change,{
data$data<-WorldPhones[,input$region]
})
output$phonePlot <- renderPlot({
if(!is.null(data$data))
barplot(data$data*1000,
ylab="Number of Telephones",
xlab="Year")
})
}
shinyApp(ui = ui, server = server)