简体   繁体   English

根据 Shiny App 的输入运行不同的数据

[英]Running different data based on the input for Shiny App

I am running a Shiny Apps which takes an input from the user.我正在运行一个 Shiny Apps,它接受用户的输入。 After taking the user input, it has to change the output accordingly.接受用户输入后,它必须相应地更改输出。

The code looks like this:代码如下所示:

#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")
  )  
}

The program stops running when the script is as such.当脚本如此时程序停止运行。 How do you control the output by the user input?你如何通过用户输入控制输出? Need some guidance.需要一些指导。

Here is an example this might help.这是一个可能会有所帮助的示例。

server <- function(input, output) {

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


    data <- f1

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

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

    }

     data
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM