我正在制作一个闪亮的应用程序,以显示来自多个r程序包的不同类型的面板图。
当我尝试下载剧情时,该应用程序按预期工作。每次我下载其中一个地块时,结果都是空的或无法打开。
我已经尝试了好几天了,但是没有运气。 希望任何人都可以帮助
ui.R
## Script setup
library(ggrepel)
library(grid)
library(openxlsx)
library(shiny)
library(shinythemes)
library(clipr)
library(dplyr)
library(stringr)
library(ggplot2) # for the diamonds dataset
library(shinycssloaders)
# Define UI for data upload app ----
ui <- fluidPage(
tags$style("
body {
-moz-transform: scale(0.9, 0.9); /* Moz-browsers */
zoom: 0.9; /* Other non-webkit browsers */
zoom: 90%; /* Webkit browsers */
}"),
# App title ----
titlePanel("Panelplot generator"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Select a file --
fileInput("upload_bestand", "Upload Excel-bestand met data",
multiple = FALSE,
accept = c("xls",
"xlsx",
".xlsx")),
# Button
#downloadButton("Download_Uploadsheet_Panelplot.csv", "Download Uploadsheet"),
# A select input for selecting subset
downloadButton("Jackknife.png", "Download Panelplot"),
# Input: Checkbox wel of geen titel ----
#checkboxInput("header", "Uploadsheet is inclusief titelrij", TRUE),
# Horizontal line ----
#tags$hr(),
# Input: Decimaal ----
# radioButtons("sep", "Decimaalteken",
## choices = c(Komma = ",",
# Punt = "."),
# selected = ","),
# Horizontal line ----
tags$hr(),
#Input: Plotkeuze ----
radioButtons("Plotkeuze", "Panelplot Model",
choices = c("Panelplot met alleen bovenreeks" = "Panel_boven",
"Panelplot met onder- en bovenreeks" = "Panel_alles",
"Panelplot met Correlatie coefficient" = "Panel_regres",
"Panelplot met Correlatie-ellipsen" = "Panel_elips"),
selected = "Panel_alles")
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Tabset w/ plot, summary, and table ----
tabsetPanel(type = "tabs",
tabPanel("Data upload", DT::dataTableOutput("data_upload")),
tabPanel("Data samenvatting", DT::dataTableOutput("data_sam")),
tabPanel("Panelplots", plotOutput("Panelplots",width = "100%", height = "800px")%>% withSpinner(color="orange")),
tabPanel("Handleiding App", tableOutput("handleiding"))
)
)
)
)
server.R
## Script setup
library(ggrepel)
library(grid)
library(readxl)
library(shiny)
library(ggthemes)
library(lubridate)
library(shinythemes)
library(clipr)
library(dplyr)
library(stringr)
library(tidyr)
library(skimr)
library(DT)
library(psych)
library(tools)
server <- function(input, output) {
output$data_upload <- DT::renderDataTable(DT::datatable({
req(input$upload_bestand)
inFile <<- input$upload_bestand
if(is.null(inFile))
return(NULL)
keuze<-3
tryCatch(
data_raw <<- readxl::read_excel(input$upload_bestand$datapath,sheet = keuze),
finally = print("Het bestand wordt niet herkend als .xlsx of .xls-bestand"))
# Data aanpassen voor weergeven in app
data_display <- data_raw
}))
# Data samenvatting----
output$data_sam <- DT::renderDataTable(DT::datatable({
req(input$upload_bestand)
data_summ_raw_1<-skim(data_raw)
data_summ_fin<-data_summ_raw_1[,-c(4,5)] %>%
filter(type=="numeric") %>%
filter(stat != "hist")%>%
filter(stat != "p25")%>%
filter(stat != "p75")%>%
filter(stat != "complete")%>%
spread(stat, formatted)
colnames(data_summ_fin)<-c("Kolomnaam","Datatype","Gemiddelde","No. ontbrekende", "No. rijen",
"Minimum","Maximum","Mediaan", "Standaard deviatie")
data_summ_fin<-data_summ_fin[,c(1,2,5,4,3,9,6,8,7)]
}))
# Panelplot weergeven
plotInput <- reactive({
data_plot<-Filter(is.numeric, data_raw)
if (input$Plotkeuze == "Panel_alles"){
panelplot<-pairs(data_plot, pch = 19)
} else if (input$Plotkeuze == "Panel_boven"){
panelplot<-pairs(data_plot, pch = 19, lower.panel = NULL)
} else if (input$Plotkeuze == "Panel_regres"){
# Correlation panel
panel.cor <- function(x, y){
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- round(cor(x, y), digits=2)
txt <- paste0("R = ", r)
cex.cor <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex.cor * r)
}
# Customize upper panel
upper.panel<-function(x, y){
points(x,y, pch = 19)
}
# Create the plots
panelplot<-pairs(data_plot,
lower.panel = panel.cor,
upper.panel = upper.panel)
} else if (input$Plotkeuze == "Panel_elips"){
panelplot<-pairs.panels(data_plot,
method = "pearson", # correlation method
hist.col = "orange",
density = TRUE, # show density plots
ellipses = TRUE) # show correlation ellipses
}
panelplot
})
output$Panelplots <- renderPlot({
print(plotInput())
})
# Template uploadsheet downloaden ----
output$Download_Uploadsheet_Jackknife.csv<- downloadHandler(
filename = "Uploadsheet_Jackknife.csv",
content = function(file) {
uploadsheet<-as.data.frame(matrix(nrow=1,ncol=4))
colnames(uploadsheet)=c("Storingsno.","ComponentNaam","DowntimePerStoring","DatumStoring")
str(uploadsheet)
write.csv(uploadsheet,file,row.names = FALSE)
})
output$plot_down <- downloadHandler(
filename = "iris.png",
content = function(file) {
png(file)
print(plotInput())
dev.off()
}
)
}
答案 0 :(得分:0)
我不知道其背后的原理,但将plotInput从反应型更改为静态功能,然后将其插入到output $ panelplots中即可达到目的