Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R shiny,shinyjs,删除绘图,如果单击按钮,则再次绘制绘图_R_Shiny_K Means_Shinyjs - Fatal编程技术网

R shiny,shinyjs,删除绘图,如果单击按钮,则再次绘制绘图

R shiny,shinyjs,删除绘图,如果单击按钮,则再次绘制绘图,r,shiny,k-means,shinyjs,R,Shiny,K Means,Shinyjs,我有一个应用程序,一旦用户点击一个特定按钮(“运行k-means”),它就会用k-means集群绘制旧的Faithul数据。现在,我想添加一个按钮,再次删除绘图(“删除绘图”)。下列的 我试过这个: library(shiny) ui <- fluidPage( actionButton(inputId = "run_kmeans", label = "run k-means"), actionButton(inputId = "remove_plot", label = "remove

我有一个应用程序,一旦用户点击一个特定按钮(“运行k-means”),它就会用k-means集群绘制旧的Faithul数据。现在,我想添加一个按钮,再次删除绘图(“删除绘图”)。下列的 我试过这个:

library(shiny)

ui <- fluidPage(
actionButton(inputId = "run_kmeans", label = "run k-means"),
actionButton(inputId = "remove_plot", label = "remove plot"),
conditionalPanel("output.show", plotOutput("plot"))
)

server <- function(input, output) {
v <- reactiveValues(show = TRUE)

clusters <- eventReactive(input$run_kmeans, {
kmeans(faithful, 2)
v$show <- TRUE
})

output$plot <- renderPlot({plot(faithful, col = clusters()$cluster)})

output$show <- reactive({
return(v$show)
})

observeEvent(input$remove_plot, {v$show <- 0})

}

shinyApp(ui, server)

但是现在,如果单击“run k-means”,绘图将“永远”隐藏,并且不会再次显示-我是否错误地放置了
show()
函数?谁能在这两种方法中的任何一种(或两者)上帮助我?

将show调用放在一个观察者事件中,就像你对hide调用所做的那样:
observeEvent(输入$run\u kmeans,{show(“plot”)})
这样做了。
library(shiny)
library(shinyjs)

ui <- fluidPage(
  useShinyjs(),
  actionButton(inputId = "run_kmeans", label = "run kmeans"),
  actionButton(inputId = "remove_plot", label = "remove plot"),
  plotOutput("plot")
)

server <- function(input, output) {
  clusters <- eventReactive(input$run_kmeans, {kmeans(faithful, 2)})
  output$plot <- renderPlot({show(plot(faithful, col = clusters()$cluster))})

  observeEvent(input$remove_plot, {hide("plot")})
  }

shinyApp(ui, server)