Ich möchte eine Funktion in einer Shiny
App implementieren. Meine eigene Funktion get_calculate()
hat die Argumente Daten und Toleranz als Eingabe und retruns list
mit data.frame
und plot
.glänzende App mit eigener Funktion
Ich möchte die Ausgabe in Abhängigkeit von der Toleranz zeigen. In meiner Serverfunktion verwende ich reactive()
, um get_calculate()
zu laufen, aber es funktioniert nicht.
Wenn ich schreibe in renderPlot()
und renderDataTable()
get_calculate()
funktioniert. Für große Datensätze ist es jedoch ineffizient, weil Shiny
zweimal get_calculate()
ausführen muss.
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)
versuchen Sie 'Quelle (" 01-get_calculate.R ", local = TRUE') –
Danke für Ihre Antwort. Die glänzende App funktioniert immer noch nicht. Fehlermeldung in glänzenden App ist: "Objekt des Typs 'Schließung' ist nicht Teilmenge" – user5308682
vielleicht 'infile <- req (Eingabe $ Datendatei)' anstelle der 'if (is.null (infile))' – user5029763