缺少参数"sidebar",创建闪亮脚本时没有默认值



我正在为一个基于几个变量预测吗啡消耗的应用程序创建一个闪亮的应用程序。当我试图运行应用程序时,我收到一个侧边栏错误消息,说明我缺少脚本来创建侧边栏("参数"缺少,没有默认值")。这是我的ui和服务器脚本。

#Load libraries
library(shiny)
library(shinydashboard)
library(ggplot2)
library(dplyr)
library(randomForest)
library(Metrics)
#R Shiny ui
ui <- dashboardPage(dashboardHeader(title = 'Morphine Consumption Explorer', titleWidth = 290))

#Sidebar layout
dashboardSidebar(sidebarMenu(id = "menu", sidebarMenuOutput("menu")))
sidebarMenu(menuItem("Plots", tabName = "plots", icon = icon('poll')),
menuItem("Dashboard", tabName = "dash", icon = icon('tachometer-alt')),
menuItem("Prediction", tabName = "pred", icon = icon('search')))
#pick variables  
#Tabs layout
dashboardBody(tags$head(tags$style(HTML('.main-header .logo {font-weight: bold;}'))))
tabItems()

#Plots tab content
tabItem('plots', 
#Histogram filter
box(status = 'primary', title = 'Filter for the histogram plot', 
selectInput('num', "Numerical variables:", c("Age", "BMI", "IV_Fluids", "Operative_times", "Blood_loss", "Time_to_Aldrete_9", "morphine_consumption_24h1",
"VAS_basalR", "VAS_basalM", "VAS_2hrR", "VAS_2hrM", "VAS_4hrM", "VAS-4hrR",
"VAS_8hrR", "VAS_8hrM", "VAS_12hrR", "VAS_12hrM", "VAS_16hrR", "VAS_16hrM", 
"VAS_24hrR", "VAS_24hrM", "QOR_psychological_support", "QOR_emotional_state",
"QOR_Physical_comfort", "QOR_physical_independence", "QOR_Pain", "Total")),
footer = 'Histogram plot for numerical variables'),
#Frequency plot filter
box(status = 'primary', title = 'Filter for the frequency plot',
selectInput('cat', 'Categorical variables:', c("ASA", "Postoperative_vomiting", "Sedation_0to8h", "Sedation_9to16h", "Sedation_17to24h")),
footer = 'Frequency plot for categorical variables'),
#Boxes to display the plots
box(plotOutput('histPlot')),
box(plotOutput('freqPlot')))

#Prediction tab content
tabItem('pred',
#Filters for categorical variables 
box(title = 'Categorical variables', 
status = 'primary', width = 12, 
splitLayout(
tags$head(tags$style(HTML(".shiny-split-layout > div {overflow: visible;}"))),
cellWidths = c('0%', '19%', '4%', '19%', '4%', '19%', '4%', '19%', '4%', '8%'),
selectInput( 'p_group', 'group', c("0", "30", "60", "90")),
div(),
selectInput('p_ASA', 'ASA', c('1', '2', '3')),
div(),
selectInput( 'p_Sedation_17to24h', 'Ramsey Sedation at 17-24h', c('1', '2', '3', '4')),
div(),
radioButtons( 'p_Postoperative_vomiting', 'PONV', c('Yes', 'No')))),
#Filters for numeric variables
box(title = 'Numerical variables',
status = 'primary', width = 12,
splitLayout(cellWidths = c('22%', '4%','21%', '4%', '21%', '4%', '21%'),
sliderInput( 'p_Age', 'Age (year)', min = 0, max = 100, value = 0),
div(),
numericInput( 'p_BMI', 'BMI', 0),
div(),
numericInput( 'p_VAS_24hrM', 'VAS with Movement at 24hr', 0),
div(),
numericInput( 'p_QOR_psychological_support', 'QOR - Psychological Support', 0),
div(),
numericInput( 'p_QOR_Pain', 'QOR - Pain', 0),
numericInput( 'p_QOR_Physical_comfort', 'QOR - Physical Comfort', 0),
div(),
)),

#Box to display the prediction results
box(title = 'Prediction result',
status = 'success', 
solidHeader = TRUE, 
width = 4, height = 260,
div(h5('Morphine Consumption (mg):')),
verbatimTextOutput("value", placeholder = TRUE),
div(h5('Range of Morphine Consumption:')),
verbatimTextOutput("range", placeholder = TRUE),
actionButton('cal','Calculate', icon = icon('calculator'))),
#Box to display information about the model
box(title = 'Model explanation',
status = 'success', 
width = 8, height = 260,
helpText('The following model will predict the total amount of morphine consumed by age, BMI, Visual Analog Scale at 24 hours with movement, and Quality of Recovery.'),
helpText('The name of the dataset used to train the model is "Short-term efficacy of preoperative Duloxetine for patients subjected to modified radical mastectomy A dose ranging randomized controlled trial", taken from the UCI Machine Learning Repository website. The data contains 17,379 observations and 16 attributes related to time and weather conditions.'),
helpText(sprintf('The prediction is based on a random forest supervised machine learning model. Furthermore, the models deliver a mean absolute error (MAE) of %s morphine consumed, and a root mean squared error (RMSE) of %s total number of morphine consumed.', round(mae_rf, digits = 0), round(rmse_rf, digits = 0)))))

# R Shiny server
server <- shinyServer(function(input, output) {

#Univariate analysis
output$histPlot <- renderPlot({...})
output$freqPlot <- renderPlot({...})
#Dashboard analysis
output$linePlot <- renderPlot({...})
output$barPlot <- renderPlot({...})
#Prediction model
#React value when using the action button
a <- reactiveValues(result = NULL)

observeEvent(input$cal, {
#Copy of the test data without the dependent variable
test_pred <- test_set[-10]

#Dataframe for the single prediction
values = data.frame(mnth = input$p_mnth, 
Group = input$p_group,
ASA = input$p_ASA,
Sedation_17to24hr = input$p_Sedation_17to24h,
PONV = input$p_Postoperative_vomiting)

#Include the values into the new data
test_pred <- rbind(test_pred,values)

#Single preiction using the randomforest model
a$result <-  round(predict(model_rf, 
newdata = test_pred[nrow(test_pred),]), 
digits = 0)
})

output$value <- renderText({
#Display the prediction value
paste(a$result)
})

output$range <- renderText({
#Display the range of prediction value using the MAE value
input$cal
isolate(sprintf('(%s) - (%s)', 
round(a$result - mae_rf, digits = 0),
round(a$result + mae_rf, digits = 0)))
})

})
shinyApp(ui, server)

感谢您的反馈。

谢谢。

我试着在运行应用程序后操纵侧边栏脚本。我期待一个闪亮的应用程序,允许我描绘变量和估计吗啡消耗。

headersidebarbody函数需要作为参数传递给dashboardPage(header, sidebar, body, title = NULL)函数。请检查以下内容:

# Load libraries
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(ggplot2)
library(dplyr)
library(randomForest)
library(Metrics)
# R Shiny ui
ui <- dashboardPage(header = dashboardHeader(title = 'Morphine Consumption Explorer', titleWidth = 290),
sidebar = dashboardSidebar(sidebarMenu(menuItem("Plots", tabName = "plots", icon = icon('poll')),
menuItem("Dashboard", tabName = "dash", icon = icon('tachometer-alt')),
menuItem("Prediction", tabName = "pred", icon = icon('search')), id = "menu")),
body = dashboardBody(tags$head(tags$style(HTML('.main-header .logo {font-weight: bold;}'))),
tabItems(

#Plots tab content
tabItem('plots', 
#Histogram filter
box(status = 'primary', title = 'Filter for the histogram plot', 
selectInput('num', "Numerical variables:", c("Age", "BMI", "IV_Fluids", "Operative_times", "Blood_loss", "Time_to_Aldrete_9", "morphine_consumption_24h1",
                              "VAS_basalR", "VAS_basalM", "VAS_2hrR", "VAS_2hrM", "VAS_4hrM", "VAS-4hrR",
                              "VAS_8hrR", "VAS_8hrM", "VAS_12hrR", "VAS_12hrM", "VAS_16hrR", "VAS_16hrM", 
                              "VAS_24hrR", "VAS_24hrM", "QOR_psychological_support", "QOR_emotional_state",
                              "QOR_Physical_comfort", "QOR_physical_independence", "QOR_Pain", "Total")),
footer = 'Histogram plot for numerical variables'),
#Frequency plot filter
box(status = 'primary', title = 'Filter for the frequency plot',
selectInput('cat', 'Categorical variables:', c("ASA", "Postoperative_vomiting", "Sedation_0to8h", "Sedation_9to16h", "Sedation_17to24h")),
footer = 'Frequency plot for categorical variables'),
#Boxes to display the plots
box(plotOutput('histPlot')),
box(plotOutput('freqPlot'))),


#Prediction tab content
tabItem('pred',
#Filters for categorical variables 
box(title = 'Categorical variables', 
status = 'primary', width = 12, 
splitLayout(
tags$head(tags$style(HTML(".shiny-split-layout > div {overflow: visible;}"))),
cellWidths = c('0%', '19%', '4%', '19%', '4%', '19%', '4%', '19%', '4%', '8%'),
selectInput( 'p_group', 'group', c("0", "30", "60", "90")),
div(),
selectInput('p_ASA', 'ASA', c('1', '2', '3')),
div(),
selectInput( 'p_Sedation_17to24h', 'Ramsey Sedation at 17-24h', c('1', '2', '3', '4')),
div(),
radioButtons( 'p_Postoperative_vomiting', 'PONV', c('Yes', 'No')))),
#Filters for numeric variables
box(title = 'Numerical variables',
status = 'primary', width = 12,
splitLayout(cellWidths = c('22%', '4%','21%', '4%', '21%', '4%', '21%'),
sliderInput( 'p_Age', 'Age (year)', min = 0, max = 100, value = 0),
div(),
numericInput( 'p_BMI', 'BMI', 0),
div(),
numericInput( 'p_VAS_24hrM', 'VAS with Movement at 24hr', 0),
div(),
numericInput( 'p_QOR_psychological_support', 'QOR - Psychological Support', 0),
div(),
numericInput( 'p_QOR_Pain', 'QOR - Pain', 0),
numericInput( 'p_QOR_Physical_comfort', 'QOR - Physical Comfort', 0),
div(),
)),

#Box to display the prediction results
box(title = 'Prediction result',
status = 'success', 
solidHeader = TRUE, 
width = 4, height = 260,
div(h5('Morphine Consumption (mg):')),
verbatimTextOutput("value", placeholder = TRUE),
div(h5('Range of Morphine Consumption:')),
verbatimTextOutput("range", placeholder = TRUE),
actionButton('cal','Calculate', icon = icon('calculator'))),
#Box to display information about the model
box(title = 'Model explanation',
status = 'success', 
width = 8, height = 260,
helpText('The following model will predict the total amount of morphine consumed by age, BMI, Visual Analog Scale at 24 hours with movement, and Quality of Recovery.'),
helpText('The name of the dataset used to train the model is "Short-term efficacy of preoperative Duloxetine for patients subjected to modified radical mastectomy A dose ranging randomized controlled trial", taken from the UCI Machine Learning Repository website. The data contains 17,379 observations and 16 attributes related to time and weather conditions.'),
helpText(sprintf('The prediction is based on a random forest supervised machine learning model. Furthermore, the models deliver a mean absolute error (MAE) of %s morphine consumed, and a root mean squared error (RMSE) of %s total number of morphine consumed.', round(mae_rf, digits = 0), round(rmse_rf, digits = 0)))
))
)
),
title = 'Morphine Consumption Explorer',
skin = "blue")

server <- function(input, output, session) {}
shinyApp(ui, server)

相关内容

  • 没有找到相关文章

最新更新