【问题标题】:Running different data based on the input for Shiny App根据 Shiny App 的输入运行不同的数据
【发布时间】:2019-12-06 03:22:23
【问题描述】:

我正在运行一个闪亮的应用程序,它接受用户的输入。接受用户输入后,它必须相应地更改输出。

代码如下所示:

#Shiny Header/Sidebar/Body
sidebar=dashboardSidebar(sidebarMenu(
  menuItem("Dashboard", tabName = "1", icon = icon("bar-chart")),
  selectInput("Category", "Select Desk", c("desk1", "desk2"))
))
body=dashboardBody(
  tabItems(tabItem(tabName = "Risk",uiOutput('output1'),
                    fluidRow(column(width = 3,box(title = "Summary of EQ Delta", width = NULL, collapsible = TRUE, solidheader = TRUE,status = "primary",tableOutput("EOD"))),column(width = 3,box(title = "Summary of FX Delta", width = NULL,  collapsible = TRUE, solidheader = TRUE,status = "primary",tableOutput("FX")))),
                    fluidRow(column(width = 8,box(title = "Exposures by Indices", width = NULL, collapsible = TRUE, solidheader = TRUE,status = "primary",plotOutput("Chart1"))))
                   )
          )
)
ui <- dashboardPage(header,sidebar,body)

#Shiny Server
server <- function(input, output,session) {
  if(input$RiskCategory == "desk 1")
  (
     observeEvent(reactiveTimer(30000)(),{ # Trigger every 30 seconds
        source("script1.R")
    })
    output$output1 <- renderUI({
        invalidateLater(30000, session)
        h1(paste("Desk1"))
    })
  )
  else
  (
    print("desk2")
  )  
}

当脚本如此时程序停止运行。你如何控制用户输入的输出?需要一些指导。

【问题讨论】:

  • 我建议你看看关于闪亮的教程,特别是关于reactivity的教程;您对input$RiskCategory 的使用需要在reactiveobserve(或相关)块内,而不是在服务器函数中单独使用。
  • 可以举例说明应该如何做吗?

标签: r shiny shinydashboard


【解决方案1】:

这是一个可能有帮助的示例。

server <- function(input, output) {

output$table <- DT::renderDataTable(DT::datatable({


    data <- f1

    if (input$RiskCategory!= "All") {

        data <- data[data$RiskCategory== input$RiskCategory,]

    }

     data
}

【讨论】:

  • 感谢示例,但​​我需要在 if-else 中呈现输出
猜你喜欢
  • 1970-01-01
  • 2017-05-17
  • 1970-01-01
  • 2021-08-28
  • 1970-01-01
  • 2020-08-30
  • 2020-08-02
  • 1970-01-01
  • 2021-07-27
相关资源
最近更新 更多