R 使用“闪亮”按钮在布局之间进行反应性切换
如何根据用户输入在Shiny中的页面布局之间切换?例如,我想在边栏布局和wellpanel布局之间切换,以使图形能够跨越整个页面 到目前为止,我所拥有的一切似乎都在工作的边缘,但我认为问题在于我不能重用从R 使用“闪亮”按钮在布局之间进行反应性切换,r,shiny,reactive-programming,R,Shiny,Reactive Programming,如何根据用户输入在Shiny中的页面布局之间切换?例如,我想在边栏布局和wellpanel布局之间切换,以使图形能够跨越整个页面 到目前为止,我所拥有的一切似乎都在工作的边缘,但我认为问题在于我不能重用从renderUI创建的接口。举个例子, library(shiny) shinyApp( shinyUI( fluidPage( radioButtons('layout', 'Layout:', choices=c('Sidebar', 'We
renderUI
创建的接口。举个例子,
library(shiny)
shinyApp(
shinyUI(
fluidPage(
radioButtons('layout', 'Layout:', choices=c('Sidebar', 'WellPanel'), inline=TRUE),
conditionalPanel(
condition = "input.layout == 'Sidebar'",
uiOutput('sidebarUI')
),
conditionalPanel(
condition = "input.layout == 'WellPanel'",
uiOutput('wellUI')
)
)
),
shinyServer(function(input, output) {
output$sidebarUI <- renderUI({
sidebarLayout(
sidebarPanel(
uiOutput('ui')
),
mainPanel(
plotOutput('plot')
)
)
})
output$wellUI <- renderUI({
fluidRow(
column(12, plotOutput('plot')),
column(12, wellPanel(uiOutput('ui')))
)
})
output$ui <- renderUI({
list(
checkboxInput('inp1', 'Some stuff'),
sliderInput('inp2', 'Some more stuff', 0, 10, 5)
)
})
output$plot <- renderPlot({ plot(1) })
})
)
库(闪亮)
shinyApp(
新余(
流动摄影(
单选按钮('layout','layout:',choices=c('Sidebar','WellPanel'),inline=TRUE),
条件板(
condition=“input.layout==”边栏“,
uiOutput('sidebarUI')
),
条件板(
condition=“input.layout=”井面板“,
uiOutput('wellUI')
)
)
),
shinyServer(功能(输入、输出){
output$sidebarUIHi您不能在ui中调用一个输出两次(或更多),这就是为什么这不起作用的原因,相反,您可以在服务器中这样做:
library(shiny)
shinyApp(
shinyUI(
fluidPage(
radioButtons('layout', 'Layout:', choices=c('Sidebar', 'WellPanel'), inline=TRUE),
uiOutput('general_ui')
)
),
shinyServer(function(input, output) {
output$general_ui <- renderUI({
if (input$layout == "Sidebar") {
sidebarLayout(
sidebarPanel(
uiOutput('ui')
),
mainPanel(
plotOutput('plot')
)
)
} else if (input$layout == "WellPanel") {
fluidRow(
column(12, plotOutput('plot')),
column(12, wellPanel(uiOutput('ui')))
)
}
})
output$ui <- renderUI({
list(
checkboxInput('inp1', 'Some stuff'),
sliderInput('inp2', 'Some more stuff', 0, 10, 5)
)
})
output$plot <- renderPlot({ plot(1) })
})
)
output$ui <- renderUI({
list(
checkboxInput('inp1', 'Some stuff'),
if (is.null(input$inp2)) {
sliderInput('inp2', 'Some more stuff', 0, 10, 5)
} else {
sliderInput('inp2', 'Some more stuff', 0, 10, input$inp2)
}
)
})
`%||%` <- function(a, b) {
if (!is.null(a)) a else b
}
我可以想象你的UI会更复杂。你可能会为验证一个小部件编写一个函数。我稍后会研究它。
`%||%` <- function(a, b) {
if (!is.null(a)) a else b
}