0
我想使用动态接口使用selectInput
小工具更改ggvis
阴谋的图层。问题是,当我在创建绘图后选择不同的图层时,它会发生变化,但它会很快消失。以下是代码的简化版本,以显示省略所有额外动态内容的问题。我只是从数据集中绘制一些数值。我添加了几个selectInput
小部件,让用户选择什么类型的情节以及何时显示情节。请注意,我需要包含renderUI
中的所有元素。dingically更改ggvis阴谋层
library(shiny)
library(ggvis)
runApp(list(
ui = shinyUI(
fluidPage(
sidebarLayout(
sidebarPanel(uiOutput("controls")),
mainPanel(uiOutput("Plot_UI")
)
)
)
),
server = function(input, output, session) {
dat <- reactive(iris[sample(nrow(iris),input$numbers),])
buildPlot <- function(layer = 'points'){
if (layer=='points'){
dat %>%
ggvis(~Sepal.Width, ~Sepal.Length) %>%
layer_points() %>%
bind_shiny("ggvis1")
} else {
dat %>%
ggvis(~Sepal.Width, ~Sepal.Length) %>%
layer_bars() %>%
bind_shiny("ggvis1")
}
}
output$controls <- renderUI({
div(
sliderInput("numbers", label = "Number of values to plot?", min = 1, max = 150, value = 75),
selectInput('plot_type', 'Plot Type', c("points","bars")),
selectInput("show", 'Show plot?', c('No','Yes'))
)
})
output$Plot_UI <- renderUI({
if (!is.null(input$show) && input$show == 'Yes'){
cat("Plot_UI -> Build plot\n")
buildPlot(input$plot_type)
div(
uiOutput("ggvis_ui"),
ggvisOutput("ggvis1")
)
}
})
}
))
再次看到图上的唯一方法是通过选择不显示的情节,后来选择显示再次使用“显示情节” selectInput
的情节。
我不知道这是一个错误还是我做错了。任何帮助或建议真的很感激。
谢谢,它正在工作。现在唯一的问题是,当我隐藏并尝试再次显示剧情时,它不会出现。 – Geovany
嗯,我明白了。我编辑了代码来解决这个问题。 –
太棒了,现在一切正常。谢谢你的帮助。 – Geovany