有这段代码。我无法让它绘制图表两次。尝试按以下顺序输入文本框的值:
- 1、2 和 6
- 1、6 和 2
例如 1,它只绘制一次图表。例如 2,它只绘制了两次(因为它们是不同的图表)有什么技巧可以让我根据用户的需要多次工作吗?
ui <- fluidPage(
tagList( textInput(inputId = "textbox", label = NULL,value = ""),actionButton("go", "Go"),uiOutput("ui")))
server <- function(input, output) {
observeEvent(input$go, {
output$plot1 <- renderGvis({
df <- data.frame(country=c("US", "GB", "BR"),
val1=c(10,33,44),
val2=c(23,122,342))
Sys.sleep(0.3)
gvisBarChart(df, xvar="country", yvar=c("val1", "val2"),
options=list(isStacked=TRUE, height = 300, width = 400))
})
output$plot2 <- renderGvis({
df <- data.frame(country=c("IND", "RUS", "BR"),
val1=c(10,3333,244),
val2=c(2344,122,342))
Sys.sleep(0.3)
gvisBarChart(df, xvar="country", yvar=c("val1", "val2"),
options=list(isStacked=TRUE, height = 300, width = 400))
})
output$ui <- renderUI({
if(isolate(as.numeric(input$textbox)) %in% c(1,2,3)){
box(title = "ABC", width = 10, height = 550, htmlOutput("plot1",height = 500))
}else{
box(title = "DEF", width = 4, height = 550, htmlOutput("plot2",height = 500))
}
})
})
}