1
私はshinyappを持っています。他のオブジェクト/入力(他の操作を実行するボタンで、その結果は簡単には追跡できません。 )。だから私はボタンの入力を使わなければならなかった。すべてのボタンのコードを書き直すことなくメインオブジェクトを更新する方法はありますか?私の例では、私は2回を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)