【发布时间】:2015-10-19 15:02:30
【问题描述】:
我想制作一个反应式显示,根据选择的输入选择器的值显示不同数量的图。在 mtcars 数据集的情况下,假设我想让用户选择 between 切割 Nr。齿轮或 Nr。 Carburatos 用于要生产的地块。
查看unique(mtcars$gear),我们看到它有4 3 5 3 个可能的值,而unique(mtcars$carb) 有4 1 2 3 6 8 6 个可能的值。因此,我想在选择 Nr. of Carburators 时生成 6 个单独的图,而在选择 Nr. of Gears 时只生成 3 个图。我玩过conditionalPanel,但在我在选择器之间切换一两次后它总是会爆炸。帮忙?
闪亮的用户界面:
library(shiny)
library(googleVis)
shinyUI(bootstrapPage(
selectInput(inputId = "choosevar",
label = "Choose Cut Variable:",
choices = c("Nr. of Gears"="gear",
"Nr. of Carburators"="carb")),
htmlOutput('mydisplay') ##Obviously I'll want more than one of these...
# conditionalPanel(...)
))
闪亮的服务器:
shinyServer(function(input, output) {
#Toy output example for one out of 3 unique gear values:
output$mydisplay <- renderGvis({
gvisColumnChart(
mtcars[mtcars$gear==4,], xvar='hp', yvar='mpg'
)
})
})
【问题讨论】: