【发布时间】:2020-01-04 23:21:35
【问题描述】:
我在 R 中有一个完整的函数,它接受一些输入参数并返回一个矩阵。我想在 Shiny 应用程序上构建相同的内容。函数的输入参数应该是滑块输入,输出应该是动态的。
我尝试使用反应函数来改变输入。
names<- c("A", "B", "C", "D", "E")
ages<- c(25,24,23,22,21)
salary<- c(60000,32000,37000,15000,15000)
data<- data.frame(names,ages, salary)
header<- dashboardHeader(title="Dynamic")
sidebar<- dashboardSidebar(sidebarMenu(
id="id",
sliderInput("age","AGE",min = 0, max = 50, value = "20")
))
body<- dashboardBody(box(
dataTableOutput("view")
))
ui<- dashboardPage(header, sidebar, body)
try_function<- function(age){
to_show<- data %>% filter(ages>age)
return(to_show)
}
server<- function(input, output, session) {
output$view <- renderDataTable({
reactive({try_function(input$age)
})
})
}
shinyApp(ui, server)
任何人都可以帮助解决这个问题。 假设如果我有多个输入,那么这段代码应该如何变化。
我希望输出会根据闪亮应用上的参数而有所不同。这不会给我任何错误,但也不会在 Shiny 上显示任何输出。
【问题讨论】: