[英]Using Shiny to dispay conditional ggvis OR ggplot
嗨,即时通讯使用闪亮来显示一些情节。 我需要同时使用ggplot和ggvis,因为它们都有一些功能,而其他则没有。 我的问题是我想在滑块值小于100时显示ggplot,而在等于100时显示ggvis。我可以同时显示两个图,但找不到找到需要显示图的条件。 下面的代码对任何帮助表示赞赏。
shinyServer(function(input, output, session) {
vis <- reactive({
input$goButton
isolate({
output$myPlot <- renderPlot ({
ggplot(mtcars, aes(x=mpg,y=wt)) + geom_point()
})
mtcars %>% ggvis(~mpg, ~wt)
})
})
vis %>% bind_shiny("plot1")
})
SHINY UI
________
shinyUI(fluidPage(
titlePanel( "Test Plots"),
fluidRow(
column(3,actionButton("goButton", "Go!")
,checkboxInput("ckFilter", h4("Filters"), value = TRUE),
conditionalPanel( "input.ckFilter"
#,h4("Filter")#,
,sliderInput("zoom","Zoom Level", 1,10, value=1)
),
checkboxInput("ckAxes", h4("Axes"), value = FALSE),
conditionalPanel("input.ckAxes"
, selectInput("xvar", "X-axis variable", xaxis_vars, selected = "All_likelihood")
, selectInput("yvar", "Y-axis variable", yaxis_vars, selected = "All_consequence"))
,
checkboxInput("ckHighlight", h4("Highlight"), value = FALSE),
conditionalPanel("input.ckQuadrants",
numericInput("xbound", "X boundary",min=0,max=1,step=0.01, value = 0.5),
numericInput("ybound", "Y boundary", value = 75000),
numericInput("yminV", "Minimum y limit", value = 10),
numericInput("ymaxV", "Maximum y limit", value = 450000),
selectInput("ytrans", "y Transformation", c("linear", "log", "sqrt"),selected = "sqrt" ))
# ,checkboxInput("logscale", "Log scale", value = FALSE)
),
column(8,plotOutput("myPlot"),
wellPanel(
span("Number of entities selected:",textOutput("n_entities", inline = T), ", highlighted:",textOutput("n_highlighted", inline = T)
)
)
),
column(8,ggvisOutput("plot1"))
)))
您可以为此使用conditionalPanel
。 例如,要仅在缩放滑块小于10时显示plotOutput
,可以在ui.R
:
conditionalPanel(condition = "input.zoom < '10'",plotOutput("myPlot"))
对于ggvisOutput:
conditionalPanel(condition = "input.zoom == '10'",ggvisOutput("plot1"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.