我想在Shiny
應用程序中實現功能。我自己的功能get_calculate()
具有參數數據和容差作爲輸入並且使用data.frame
和plot
重新生成list
。具有自己功能的閃亮應用程序
我想根據公差顯示輸出。在我的服務器功能中,我使用reactive()
來運行get_calculate()
,但它不起作用。
如果我寫在renderPlot()
和renderDataTable()
get_calculate()
的作品。 但是,對於大型數據集,效率很低,因爲Shiny
必須運行get_calculate()
兩次。
library(shiny)
library(shinydashboard)
library(foreign)
#load my own function
source("01-get_calculate.R")
ui <- dashboardPage(
dashboardHeader(title = "Analysis"),
dashboardSidebar(
sidebarMenu(
menuItem("Load data", tabName = "data", icon = icon("database")),
menuItem("Mainboard", tabName = "Mainboard", icon = icon("dashboard"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "data",
fileInput("datafile", "Choose file",
accept = c("text/csv/rds/dbf", 'text/comma-separated-values,text/plain')),
dataTableOutput("mytable")
),
tabItem(tabName = "Mainboard",
fluidRow(
box(
title = "Input", status = "primary", solidHeader = TRUE, collapsible = TRUE,
sliderInput(inputId = "tol",
label = "Tolerance",
value = 4, min = 1, max = 15, step = 1)
)),
fluidRow(
box(
title = "Adherence Curve", status = "warning", solidHeader = TRUE, collapsible = TRUE,
plotOutput("plot_kpm")
),
box(
title = "Overview Table", status = "primary", solidHeader = TRUE, collapsible = TRUE,
tableOutput("table_kpm")
)
)
)
)
)
)
server <- function(input, output) {
filedata <- reactive({
infile <- input$datafile
if (is.null(infile)) {
return(NULL)
}
read.dbf(infile$datapath)
})
output$mytable <- renderDataTable({
filedata()
})
**test <- reactive({
get_calculate(filedata(), tolerance = input$tol)
})
output$plot_kpm <- renderPlot({
test$kpm_chart
})
output$table_kpm <- renderDataTable({
test$data_kpm[, c("Time", "numbers", "Percent")]
})**
}
shinyApp(ui = ui, server = server)
嘗試'源(「01-get_calculate.R」,本地= TRUE') –
感謝您的回答。閃亮的應用程序仍然無法正常工作。閃亮的應用程序中的錯誤消息是:「類型'關閉'的對象不是子集」 – user5308682
也許'infile < - req(input $ datafile)'而不是'if(is.null(infile))' – user5029763