r - 如何在选项卡中将两个 uiOutput 提供给 renderUI
问题描述
当我在使用闪亮时尝试喂食uiOutput
时,我在第一次运行时遇到错误。切换标签后,应用程序运行正常。renderUI
tabPanel
这是一个重现错误的最小示例
library(shiny)
ui <- fluidPage(
tabsetPanel(
tabPanel("Data",
uiOutput("moreControls")
),
tabPanel("Research",
uiOutput("moreControls2")
)
),
plotOutput("plot1")
)
server <- function(input, output) {
output$moreControls <- renderUI({
tagList(
sliderInput("mean", "Mean", -10, 10, 1),
textInput("label", "Label")
)
})
output$moreControls2 <- renderUI({
tagList(
sliderInput("sd", "SD", 1, 50, 10),
textInput("label2", "Label2")
)
})
output$plot1 <- renderPlot({
hist(rnorm(n = 100,input$mean, input$sd) , xlim = c(-100, 100) )
})
}
shinyApp(ui, server)
解决方案
@Vivek 的回答很好,但这是另一种方式:
server <- function(input, output) {
output$moreControls <- renderUI({
tagList(
sliderInput("mean", "Mean", -10, 10, 1),
textInput("label", "Label")
)
})
output$moreControls2 <- renderUI({
tagList(
sliderInput("sd", "SD", 1, 50, 10),
textInput("label2", "Label2")
)
})
outputOptions(output, "moreControls2", suspendWhenHidden = FALSE)
output$plot1 <- renderPlot({
req(input$mean, input$sd)
hist(rnorm(n = 100, input$mean, input$sd) , xlim = c(-100, 100) )
})
}
shinyApp(ui, server)
在渲染input$mean
之前也是不可用的,但是在切换到第二个选项卡之前不可用,因为滑块输入是隐藏的。uiOutput
input$sd
input$sd
推荐阅读
- javascript - 如何在 vue.js 中使用 @click 触发两个事件
- forms - 如何读取外部表单重定向?
- python - 如何通过使用wxPython在透明背景上拖动鼠标来选择要捕获的屏幕矩形?
- flutter - FutureBuilder 仅适用于 Debug
- php - nginx proxy_passing 到特定位置的 wordpress 网站
- python - Python requests.get():如果出现 Internet 连接错误,如何打印消息?
- hypervisor - 裸机管理程序及其托管的操作系统是否协调系统调用?
- android - Android Foreground Service that works while app is closed
- python - How to split a .csv without having \n added at the end of the list?
- javascript - 带有 JSON.stringify 的 sessionStorage.setItem 导致 javascript 函数失败