我正在努力构建一个闪亮的应用程序,以显示非齐次泊松过程。我有3个不同的lambda函数可供选择,并希望随时间显示lambda的图。我的解决方案是使用selectInput
,将3个函数作为值。
shinyUI(
navbarPage(
title = "Non-Homogenious Poisson Process",
tabPanel("Home",
fluidPage(
sidebarLayout(
sidebarPanel(
#select lambda function
selectInput("l_fun",
"Select Lambda Function:",
c("f(t) = |sin(t)|","f(t) = t","f(t) = log(t)")
)#end selectInput
),#end sidebarPanel
mainPanel(
textOutput("test")
)#end mainPanel
)#end sidebarLayout
)#end fluidPage
)#end tabPanel 'Home'
)#end navbarPage
)#end shinyUI
library(shiny)
shinyServer(function(input, output) {
t_intervals <- 0:100
l_calculation <- reactive({
switch(input$l_fun,
"f(t) = |sin(t)|" = function(t) abs(sin(t)),
"f(t) = t" = function(t) t,
"f(t) = log(t)" = function(t) log(t)
)#end switch
})#end l_
y <- l_calculation(t_intervals)#calculate lambda
output$test <- renderText({
paste0(y,sep=",",collapse = ",")
})
})
当我在闪亮之外运行服务器时,一切正常。但是闪亮的我得Warning: Error in l_calculation: unused argument (t_intervals)
。
自从我使用闪亮之后已经有一段时间了。此刻,我现在只是试图显示lambda值,接下来的情节将会出现。
答案 0 :(得分:1)
我尝试对您的代码进行最小的更改以使其正常工作。你不用参数调用像函数一样的反应。只能通过不带参数调用它们来访问反应变量。 &#34;论证&#34;反应变量是反应值(例如输入值或其他反应变量),但有隐含的 - 您不会将参数传递给它们。
看一下这段代码,希望它可以帮助你更好地理解它。
library(shiny)
ui <- navbarPage(
title = "Non-Homogenious Poisson Process",
tabPanel("Home",
fluidPage(
sidebarLayout(
sidebarPanel(
#select lambda function
selectInput("l_fun",
"Select Lambda Function:",
c("f(t) = |sin(t)|","f(t) = t","f(t) = log(t)")
)#end selectInput
),#end sidebarPanel
mainPanel(
textOutput("test")
)#end mainPanel
)#end sidebarLayout
)#end fluidPage
)#end tabPanel 'Home'
)#end navbarPage
server <- function(input, output, session) {
t_intervals <- 0:100
l_calculation <- reactive({
switch(input$l_fun,
"f(t) = |sin(t)|" = function(t) abs(sin(t)),
"f(t) = t" = function(t) t,
"f(t) = log(t)" = function(t) log(t)
)#end switch
})#end l_
#calculate lambda
y <- reactive({
l_function <- l_calculation()
l_function(t_intervals)
})
output$test <- renderText({
paste0(y(),sep=",",collapse = ",")
})
}
shinyApp(ui, server)