【问题标题】:R shiny force render of server side input on non active tabItem on loading加载时非活动tabItem上服务器端输入的R闪亮强制渲染
【发布时间】:2017-10-21 04:26:47
【问题描述】:

我正在使用 R shinyDashboard 创建一个网络应用程序。这个应用程序加载了一些“概述”标签作为活动的登陆。还有更多的tabItems。假设我有一个名为“设置”的特定 tabItem,可以在其中控制外观和过滤器,我想将其应用为默认值。它使用动态值,因此它必须位于服务器端。

问题是,在我不访问“设置”选项卡项之前,它的输入没有被初始化,因此“概述”选项卡项缺少数据。

下面是一个可重现的非常简单的示例,其中应用程序应在文本框中加载值“10”(实际上,它仅在访问“设置”后才会填充):

require(shiny)
require(shinydashboard)

ui<-dashboardPage(skin = "black",
    dashboardHeader(
    ),

    dashboardSidebar(
        sidebarMenu(
            menuItem("Overview", tabName = "overview"),
            menuItem("Settings", tabName = "settings")        )
        ),

        dashboardBody(
            tabItems(
                tabItem("overview",
                uiOutput("textUI")
            ),

            tabItem("settings",
                htmlOutput("FilterUI")
            )
        )
    )
)

server<-shinyServer(function(input, output,session) {

    output$FilterUI <- renderUI({
        numericInput("selected_filter", "Select value",min=0,max=20,value=10)
    })

    output$textUI <-renderUI({
        box(input$selected_filter)
    })
})

shinyApp(ui, server)

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    为要计算的变量定义 reactiveValues 或仅 reactive()。为其分配默认值 (10)。请参阅 numericInput 的 value 参数和 output$textUI 的反应值。 observeEventnumericInput 上并相应地更新reactiveValues

    【讨论】:

    • 谢谢,这个例子很完美。继续将其放入完整的代码中。
    猜你喜欢
    • 2020-03-19
    • 2016-08-15
    • 2015-01-11
    • 1970-01-01
    • 2021-06-10
    • 2014-05-06
    • 2018-04-26
    • 2021-06-19
    • 2020-06-12
    相关资源
    最近更新 更多