R 根据数字输入创建表格,然后选择输入
我正在尝试创建一个闪亮的应用程序,它可以根据兽医诊所的剂量和质量来计算药物的使用率,然后技术人员可以打印出护理表的结果表。我已经了解了如何使用selectInput加载数据集并将其显示为表格,但我需要根据动物质量和药物浓度在表格中创建速率。例如,一种药物的剂量可能为1、2、3、4或5 mcg/kg/hr,有望根据通过selectInput选择的药物进行加载,但在这种情况下,我需要通过公式计算速率,即质量*剂量/浓度。由于每种药物的剂量不同,这一点更加复杂,因此也需要根据输入进行反应 到目前为止,我所拥有的是以下内容,但我还没有能够生成任何表来响应来自闪亮应用程序的数据R 根据数字输入创建表格,然后选择输入,r,shiny,R,Shiny,我正在尝试创建一个闪亮的应用程序,它可以根据兽医诊所的剂量和质量来计算药物的使用率,然后技术人员可以打印出护理表的结果表。我已经了解了如何使用selectInput加载数据集并将其显示为表格,但我需要根据动物质量和药物浓度在表格中创建速率。例如,一种药物的剂量可能为1、2、3、4或5 mcg/kg/hr,有望根据通过selectInput选择的药物进行加载,但在这种情况下,我需要通过公式计算速率,即质量*剂量/浓度。由于每种药物的剂量不同,这一点更加复杂,因此也需要根据输入进行反应 到目前为止,
library(shiny)
drug.selections <- c("Fentanyl", "Ketamine", "Lidocaine", "Midazolam", "Metoclopramide", "Norepinephrine", "Dobutamine",
"Dopamine", "Epinephrine", "Phenylephrine", "Propofol", "Dexmedetomidine 0.1 mg/dl", "Dexmedetomidine 0.5 mg/dl", "Diltiazem", "Furosemide", "Butorphanol",
"Hydromorphine", "Morphine", "Methadone", "ACA", "Magnesium", "Alfaxalone")
drug.selections <- sort(drug.selections)
ui <- fluidPage(
headerPanel("Continuous Rate Infusion"
),
sidebarLayout(
sidebarPanel(
textInput("name", "Pet Name"),
numericInput("mass", "Pet Weight (kg)", value = 0, min =0, max = 200),
selectInput("drug", "Drug", drug.selections),
numericInput("concentration", "Concentration", value = 0, min = 0, max = 500),
numericInput("time", "How many hours needed", value = 0, min = 0, max = 40),
checkboxInput("dilute", "Dilute?", value = FALSE)
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Dose", tableOutput("dose")),
tabPanel("Diluted Dose", tableOutput("ddose")),
tabPanel("Dilution Recipe", tableOutput("recipe")),
tabPanel("Summary", textOutput("summary")),
textOutput("name"),
textOutput("mass"),
textOutput("drug")
)
)
)
)
server <- function(input, output, session) {
mass <- reactive({
get(input$mass, inherits = FALSE)
})
output$summary <- renderText({
paste (input$name, "weighs", input$mass, "kg and is on", input$concentration, "of", input$drug)
})
output$dose <- renderTable({
dose
})
output$ddose <- renderTable({
ddose
})
output$recipe <- renderTable({
recipe
})
}
shinyApp(ui, server)
我想让“剂量”选项卡生成一个剂量和速率表。我很确定我可以为其他标签做类似的事情。有人能给我指出正确的方向吗?考虑到我之前对答案的评论,我添加了一些关于每种药物的数据,这些数据可能代表每种药物的不同剂量 因此,现在,当选择药物时,将对该药物的所有预定义剂量进行计算,如下方框所示
output$dose <- renderTable({
dose = dosage_table[, input$drug]
rate = dose * as.numeric(input$mass) / as.numeric(input$concentration)
data.frame(Dose = dose, Rate = rate)
})
最终代码
用户界面
服务器
谢谢,但这不是我想要的。我知道还没有一个表剂量,这就是我想要创建的。兽医对技术人员输入剂量感到不舒服,因此这不能来自数字输入。剂量应来自所选药物。但这有点复杂,因为不同的药物有不同的剂量。例如,芬太尼的剂量为:c1,2,3,4,5,6,7,8,9,10,但氯胺酮的剂量应为c0.1,0.2,0.3,0.4,0.5。需要计算每种剂量对应的速率,并且所有速率都应在表格中表示感谢您的评论,我应该更清楚地说明,如果包含一些剂量数据,将更容易解决您的问题。让我知道更新后的答案是否更符合你的意思。
ui <- fluidPage(
headerPanel("Continuous Rate Infusion"
),
sidebarLayout(
sidebarPanel(
# add dosage
textInput("name", "Pet Name"),
numericInput("mass", "Pet Weight (kg)", value = 0, min =0, max = 200),
selectInput("drug", "Drug", drug.selections),
numericInput("concentration", "Concentration", value = 0, min = 0, max = 500),
numericInput("time", "How many hours needed", value = 0, min = 0, max = 40),
checkboxInput("dilute", "Dilute?", value = FALSE)
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Dose", tableOutput("dose")),
tabPanel("Diluted Dose", tableOutput("ddose")),
tabPanel("Dilution Recipe", tableOutput("recipe")),
tabPanel("Summary", textOutput("summary")),
textOutput("name"),
textOutput("mass"),
textOutput("drug")
)
)
)
)
server <- function(input, output, session) {
dosage_table <- data.frame('Fentanyl' = c(1,2,3,4,5,6,7,8,9,10),
'Ketamine' = c(0.1,0.2,0.3,0.4,0.5),
"Lidocaine" = c(0.1,0.2,0.3,0.4,0.5),
"Midazolam" = c(0.1,0.2,0.3,0.4,0.5),
"Metoclopramide" = c(0.1,0.2,0.3,0.4,0.5),
"Norepinephrine" = c(0.1,0.2,0.3,0.4,0.5),
"Dobutamine" = c(0.1,0.2,0.3,0.4,0.5),
"Dopamine" = c(0.1,0.2,0.3,0.4,0.5),
"Epinephrine" = c(0.1,0.2,0.3,0.4,0.5),
"Phenylephrine" = c(0.1,0.2,0.3,0.4,0.5),
"Propofol" = c(0.1,0.2,0.3,0.4,0.5),
"Dexmedetomidine 0.1 mg/dl" = c(0.1,0.2,0.3,0.4,0.5),
"Dexmedetomidine 0.5 mg/dl" = c(0.1,0.2,0.3,0.4,0.5),
"Diltiazem" = c(0.1,0.2,0.3,0.4,0.5),
"Furosemide" = c(0.1,0.2,0.3,0.4,0.5),
"Butorphanol" = c(0.1,0.2,0.3,0.4,0.5),
"Hydromorphine" = c(0.1,0.2,0.3,0.4,0.5),
"Morphine" = c(0.1,0.2,0.3,0.4,0.5),
"Methadone" = c(0.1,0.2,0.3,0.4,0.5),
"ACA" = c(0.1,0.2,0.3,0.4,0.5),
"Magnesium" = c(0.1,0.2,0.3,0.4,0.5),
"Alfaxalone" = c(0.1,0.2,0.3,0.4,0.5))
mass <- reactive({
get(input$mass, inherits = FALSE)
})
output$summary <- renderText({
paste (input$name, "weighs", input$mass, "kg and is on", input$concentration, "of", input$drug)
})
output$dose <- renderTable({
dose = dosage_table[, input$drug]
rate = dose * as.numeric(input$mass) / as.numeric(input$concentration)
data.frame(Dose = dose, Rate = rate)
})
output$ddose <- renderTable({
ddose
})
output$recipe <- renderTable({
recipe
})
}
# App
shinyApp(ui, server)