【发布时间】:2015-02-20 23:31:57
【问题描述】:
所以我对 Shiny 有点陌生,但我一生都无法弄清楚如何将滑块输入值组织到一个命名列表中。现在,我设置了一个允许 11 个输入的 UI。
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Quorom Sensing Model"),
sidebarPanel(
sliderInput("n", "Hill Coefficient:",
min=0, max=10, value=2, step=0.5),
sliderInput("K", "Max Contribution to lacI transcription:",
min=0, max=50, value=20, step=1),
sliderInput("k0_AI", "Initial Synthesis Rate of AI:",
min=0, max=5, value=3.5, step=0.1),
sliderInput("k1_AI", "Repressor dependent rate of synthesis of AI:",
min=0, max=1, value=.033, step=0.001),
sliderInput("eta", "diffusion rate of AI across cell membrane:",
min=0, max=5, value=.7, step=0.1),
sliderInput("k_deg", "extracellular AI degredation Rate:",
min=0, max=1, value=.525, step=0.001),
sliderInput("k_diff", "extracellular diffusion rate of AI:",
min=0, max=10, value=2.1, step=0.1),
sliderInput("alpha_tetR", "Alpha tetR:",
min=0, max=50, value=24, step=1),
sliderInput("alpha_cI", "Alpha cI:",
min=0, max=50, value=24, step=1),
sliderInput("alpha_lacI", "Alpha lacI:",
min=0, max=50, value=24, step=1),
sliderInput("beta", "Ratio of protein decay to mRNA decay rate:",
min=0, max=10, value=1.05, step=0.05)
),
mainPanel(
plotOutput("timeSeries"),
plotOutput("timeSeries2")
))
)
所以这些滑块输入需要输入到一个命名列表中,其中参数(命名列表)= c(n = input$n 的值,K = input$K 等)所以我可以将命名的数字列表输入到一个函数中,该函数执行生成输出所需的数学运算。
现在,我有函数 params,它根据输入变量返回一个命名列表:
params <- function(n = 2,
K=20,
k0_AI=3.5,
k1_AI=0.033,
eta=0.7,
k_deg=0.525,
k_diff=2.1,
alpha_tetR=24,
alpha_cI=24,
alpha_lacI=24,
beta=1.05){
paramlist <- c(n = n,
K = K,
k0_AI = k0_AI,
k1_AI = k1_AI,
eta = eta,
k_deg = k_deg,
k_diff = k_diff,
alpha_tetR = alpha_tetR,
alpha_cI = alpha_cI,
alpha_lacI = alpha_lacI,
beta = beta)
return(paramlist)
}
从 server.R 调用哪个,输入变量设置为滑块的 input$etc?
library(shiny)
library(ggplot2)
library(reshape2)
library(deSolve)
source("params.R")
shinyServer(function(input,output){
parameters = reactive({
params(n = input$n,
K = input$K,
k0_AI = input$k0_AI,
k1_AI= input$k1_AI,
eta = input$eta,
k_deg = input$k_deg,
k_diff = input$k_diff,
alpha_tetR = input$alpha_tetR,
alpha_cI = input$alpha_cI,
alpha_lacI =input$alpha_lacI,
beta = input$beta
)
})
eval(substitute(expr), data, enclos = parent.frame()) 中的错误: 'closure' 类型的无效 'envir' 参数
再次,我需要输入滑块值成为命名列表的一部分,其中滑块的名称 = 值,并且列表的名称可以从函数中调用。我怎么能最容易地做到这一点?谢谢!
【问题讨论】:
标签: r shiny shiny-server