Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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 从列表中删除ggvis绘图_R_Plot_Shiny_Ggvis - Fatal编程技术网

R 从列表中删除ggvis绘图

R 从列表中删除ggvis绘图,r,plot,shiny,ggvis,R,Plot,Shiny,Ggvis,我有多个ggvis图形。 我需要提供一个行动按钮,如果按钮被点击,所有的情节需要删除 下面是ui.R和server.R的示例代码: 用户界面 服务器.R library(shiny) library(ggvis) mtcars$cyl = factor(mtcars$cyl) df1 = subset(mtcars, am == 0) df2 = subset(mtcars, am == 1) shinyServer(function(input, output) { dataInput =

我有多个
ggvis
图形。 我需要提供一个行动按钮,如果按钮被点击,所有的情节需要删除

下面是
ui.R
server.R
的示例代码:

用户界面

服务器.R

library(shiny)
library(ggvis)

mtcars$cyl = factor(mtcars$cyl)
df1 = subset(mtcars, am == 0)
df2 = subset(mtcars, am == 1)

shinyServer(function(input, output) {
dataInput = reactive({
switch(input$segment,
       "K 1" = df1,
       "K 2" = df2)
})


values = function(x){
if(is.null(x)) return(NULL)
dat = dataInput()
row = dat[dat$cyl %in% unique(x$cyl), ]
paste0("Ave Weight: ", mean(row$wt),"<br />",
       "Ave Carb: ", mean(row$carb), "<br />")
}


vis1 = reactive({
dat = dataInput()
dat %>%
  group_by(cyl) %>%
  ggvis(~mpg, ~wt)  %>%
  layer_paths(stroke = ~cyl, strokeOpacity := 0.3, 
              strokeWidth := 5) %>%
  add_tooltip(values, "hover")
 })
  vis1 %>% bind_shiny("plot")

 vis2 = reactive({
dat = dataInput()
dat %>%
  group_by(cyl) %>%
  ggvis(~mpg, ~wt)  %>%
  layer_paths(stroke = ~cyl, strokeOpacity := 0.3, 
              strokeWidth := 5) %>%
  add_tooltip(values, "hover")
  })
  vis2 %>% bind_shiny("plot2")

})
库(闪亮)
图书馆(ggvis)
mtcars$cyl=系数(mtcars$cyl)
df1=子集(mtcars,am==0)
df2=子集(mtcars,am==1)
shinyServer(功能(输入、输出){
数据输入=无功({
开关(输入$段,
“K1”=df1,
“k2”=df2)
})
值=函数(x){
if(is.null(x))返回(null)
dat=数据输入()
行=dat[dat$cyl%在%唯一(x$cyl)中,]
粘贴0(“平均重量:”,平均值(行$wt),“
”, “平均碳水化合物:”,指(第$Carb行),“
”) } vis1=反应性({ dat=数据输入() dat%>% 组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别 ggvis(~mpg,~wt)%>% 图层路径(笔划=~cyl,笔划不透明度:=0.3, 冲程宽度:=5)%>% 添加工具提示(值,“悬停”) }) vis1%>%bind_(“绘图”) vis2=反应性({ dat=数据输入() dat%>% 组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别组别 ggvis(~mpg,~wt)%>% 图层路径(笔划=~cyl,笔划不透明度:=0.3, 冲程宽度:=5)%>% 添加工具提示(值,“悬停”) }) vis2%>%bind_发亮(“plot2”) })

当前输出的屏幕截图:

如果您容忍未删除但看起来像已删除的绘图,我认为很容易给
bind_shinny()
一个空白图形

服务器.R
谢谢它解决了我的问题。是否可以隐藏绘图右上角的“齿轮”图标。@user98180对不起,我不知道,至少我不能这样做。
library(shiny)
library(ggvis)

mtcars$cyl = factor(mtcars$cyl)
df1 = subset(mtcars, am == 0)
df2 = subset(mtcars, am == 1)

shinyServer(function(input, output) {
dataInput = reactive({
switch(input$segment,
       "K 1" = df1,
       "K 2" = df2)
})


values = function(x){
if(is.null(x)) return(NULL)
dat = dataInput()
row = dat[dat$cyl %in% unique(x$cyl), ]
paste0("Ave Weight: ", mean(row$wt),"<br />",
       "Ave Carb: ", mean(row$carb), "<br />")
}


vis1 = reactive({
dat = dataInput()
dat %>%
  group_by(cyl) %>%
  ggvis(~mpg, ~wt)  %>%
  layer_paths(stroke = ~cyl, strokeOpacity := 0.3, 
              strokeWidth := 5) %>%
  add_tooltip(values, "hover")
 })
  vis1 %>% bind_shiny("plot")

 vis2 = reactive({
dat = dataInput()
dat %>%
  group_by(cyl) %>%
  ggvis(~mpg, ~wt)  %>%
  layer_paths(stroke = ~cyl, strokeOpacity := 0.3, 
              strokeWidth := 5) %>%
  add_tooltip(values, "hover")
  })
  vis2 %>% bind_shiny("plot2")

})
  :
  vis2 %>% bind_shiny("plot2")    # the same up to here
  
  vis3 = mtcars %>%                   # preparation of a blank graph
    ggvis(~mpg, ~wt, opacity := 0) %>%
    layer_points() %>%
    hide_axis("x") %>%
    hide_axis("y")
  
  observeEvent(input$abutton, {    # When the button is clicked,
    bind_shiny(vis3, "plot")       # bind_shiny() reads and outputs a blank graph, vis3.
    bind_shiny(vis3, "plot2")      # When other Input is done, vis1 and vis2 return.
  }) 
  
})