2017-09-22 17 views
0

私は光沢のあるアプリケーションで作業しています。ここで関数に表示するには入力値が必要です。入力から関数内の光沢のある値

CL=4,V1=3などの名前と値を入力から取り出して、後でサーバーのモデルにフィードする必要がある機能にフィードすることです。私が取り組んでいるモデルは関数形式しか取りません。以下は私のコードです。

UI:

#Set up 
rm(list=ls()) 

library(shiny) 
library(shinydashboard) 
library(shinyBS) 
library(dplyr) 

#Design sidebar 
sidebar <- dashboardSidebar(width = 200, collapsed=TRUE, 
          sidebarMenu(id="tabs", 
             menuItem("Simulations", tabName = "Sims", icon = icon("line-chart"), selected=TRUE), 
             menuItem("Placeholder", tabName = "Place", icon = icon("square-o")) 
          )) 

#Design body 
body <- dashboardBody(
    tabItems(
    tabItem(tabName = "Sims", 
      box(collapsible=TRUE, width = 3, status = "success", solidHeader = T, title="Select Your Model", 
       radioButtons(inputId="PK_Model", label = "PK Model", selected="One_Comp", 
          choices = c("1 Compartment"="One_Comp", "2 Compartment"="Two_Comp")), 
       radioButtons(inputId="Clearance_Model",label ="Clearance Mechanism", selected="Linear", 
          choices = c("Linear"="Linear"))), 
      box(collapsible=TRUE, status = "success", solidHeader = T, title="Enter Parameter Estimates", 
         conditionalPanel(condition = "input.Clearance_Model == 'Linear'", 
              numericInput(label="Clearance (Linear) (CL; L/day)", inputId="CL", min = 0, max = NA, value = 0), 
              numericInput(label="Central volume of distribution (V1; L)", inputId="V1", min = 0, max = NA, value = 0)), 
         conditionalPanel(condition = "input.PK_Model == 'Two_Comp'", 
              numericInput(label="Inter-compartment clearance (Q; L/day)", inputId="Q", min = 0, max = NA, value = 0), 
              numericInput(label="Peripheral volume of distribution (V2; L)", inputId="V2", min = 0, max = NA, value = 0))), 
       box(collapsible=T, width=2, status = "success", solidHeader = T, title="Run", 
       actionButton('gosim','Run Sims',class='btn btn-info', icon=icon('play-circle-o','fg-lg'))), 
       box(width=5, status = "success", solidHeader = T, title="Simulated", textOutput('testprint'))))) 

#Show title and the page (includes sidebar and body) 
dashboardPage(skin=c("blue"), 
       dashboardHeader(titleWidth=900, title = "Shiny Test"), 
       sidebar, body) 

UPDATED:以下 後PoGibasの答えは、私は次のようにサーバーのコードを更新しましたが、結果は私が必要なもののようには見えません。私は、サーバー内mypar()を呼び出すときのように見えるようになる必要がある何

Server: 

    library(shiny) 
    library(shinydashboard) 
    library(shinyBS) 
    library(RxODE) 
    library(parallel) 
    library(ggplot2) 

test <- function (N1, N2, N3, N4) { 
    mypar <- function(lKa, lKdeg, N1, N2, N3, N4){ 
    Ka=exp(lKa) 
    Kdeg=exp(lKdeg) 
    V1=N1 
    CL=N2 
    Q=N3 
    V2=N4} 
    return(mypar) 
} 

    shinyServer(function(input, output, session){ 

mypar <-eventReactive(input$goSimPH20, { 
    N1=as.numeric(input$V1) 
    N2=as.numeric(input$CL) 
    N3=as.numeric(input$Q) 
    N4=as.numeric(input$V2) 
    par1 = test(N1, N2, N3, N4) 
    return(par1) 
}) 

     output$testprint <- renderText(mypar()) 

     }) 

は以下の通りです:

test <- function (lKa, lKdeg, V1, CL, Q, V2) { 
      Ka=exp(lKa) 
      Kdeg=exp(lKdeg) 
      V1=xx 
      V2=xx 
      CL=xx 
      Q=xx 
      } 

xxはUI内の任意のユーザー入力値にすることができます。

+0

私のソリューションがあなたの問題を解決する助けとなった場合は、答えを受け入れることができますので、質問を閉じることができます:) – PoGibas

+0

最小限の例としてコードを書き直してください。 https://stackoverflow.com/help/mcve – parasietje

+0

@Krinaあなたの問題を解決する助けがあれば、答えを受け入れることができますか?あなたの応答に感謝します。 – PoGibas

答えて

3

私はこれにサーバ部分を簡素化:test機能で

test <- function (V1 = 1, CL = 2, lA = 1, lB = 2) { 
    return(lA + lB + V1 + CL) 
} 

shinyServer(function(input, output, session) { 
    mypar <- reactive({ 
     V1 = as.numeric(input$V1) 
     CL = as.numeric(input$CL) 
     return(test(V1, CL)) 
    }) 
    output$testprint <- renderText(mypar()) 
}) 

は、あなたの希望の数式を追加します。ユーザー入力はV1 = as.numeric(input$V1)を使用して抽出され、testtest(V1, CL)を使用して渡されます。

+0

私はまだこれに苦しんでいます。私がmyparを呼び出して返す必要があるのは、以下のような関数です: test < - function(lA、lB、...){ A = exp(lA) B = exp(lB) V1 = xx V2 = xx CL = xx Q = xx }私はあなたの提案したアプローチを使用していくつかの異なる方法を試しましたが、まだ運がありません。 –

関連する問題