erstmal vielen Dank für dein Angebot mir zu helfen. Ich habe sehr wenig oder gar keine Erfahrungen mit Shiny. Die gezeigten Codes habe ich mir ausnahmslos selbst beigebracht bzw. aus Code schnipseln aus dem Netz zusammengestellt.
Ich möchte für mich und zukünftige Projekte ein Shiny Dashboard erstellen, in dem die ersten Schritte in deskriptiver Statistik an einem konkreten Projekt durchgeführt werden. Dazu zählt u.a. Einlesen, Manipulation, Speichern in verschiedene Dateiformate und den anschließenden Export von beliebigen Datensätzen aus Excel. Im nächsten Schritt die wichtigsten Schritte in deskriptiver Statistik u.a. Boxplots, Histogramm, Dichtekurve sowie den Export der Grafiken (svg, pdf, png, jpg). Im nächsten Schritt sollte dann erste Regressionen sowie Korrelationen und Korrelationsmatrix möglich sein.
In ferner Zukunft wäre es großartig auch multivariate Analysen erstellen zu können. Hierzu habe ich sogar ein komplettes Script im Netz gefunden.
Zurzeit habe ich nach Vorlagen bzw. den erwähnten Code Schnipseln erste Dashboards erstellen können. Leider tauchen immer wieder Fehlermeldungen auf bei denen ich aufgrund meiner mangelnden Erfahrung bzw. Programmierkenntnisse nicht weiterkomme.
Im ersten Beispiel sieht man das Dashboard mit der Überschrift und den 3 Tabs. Erster Schritt ist das Einlesen von Datensätzen. Die Codezeilen hierfür funktionieren nur für das Einlesen des xlsx Datensatzes. Trotz intensiver Suche habe ich keinen Weg gefunden andere Datenformate (csv, txt) zu importieren. Sobald ich ein anderes Datenformat als xlsx wähle kommt Fehlermeldung:
Warnung: Error in : Evaluation error: zip Datei 'C:\Users\XXX\AppData\Local\Temp\RtmpkNXK95\9824fca6478120dfec9344ea\0.txt.xlsx' kann nicht geöffnet werden.
Aber es liegt gar keine zip Datei vor! Meine konkrete Frage und Bitte um Hilfe lautet nun, wie kann ich andere Datenformate als xlsx in Shiny importieren. Damit ich erstmal eine Grundlage zum Weitermachen habe.
Hier nun der Code! Relevant ist dieser erstmal nur bis Zeile Nr. 43 dort muss Fehler Nr. 1. Hier wäre fürste Erste schon mal viel geholfen. Im Anhang ist eine Beispieldatei als csv, txt mit dabei
Code: Alles auswählen
library(shinythemes)
library(DT)
library(readxl)
library(shinyWidgets)
library(ggplot2)
library(tidyverse)
ui = (navbarPage("Statistical Evaluation", collapsible = TRUE, inverse = TRUE, theme = shinytheme("spacelab"),
tabPanel
(
"Select Data a data set",
sidebarLayout
(
sidebarPanel
(tags$head(tags$script('
Shiny.addCustomMessageHandler("myCallbackHandler",
function(typeMessage) {console.log(typeMessage)
if(typeMessage == 1){
console.log("got here");
$("a:contains(Upload a file)").click();
}
});
')),
h3("Upload a data set"),
fileInput("file1", "Choose a File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv", ".xlsx")),
# Input: Select separator ----
radioButtons("sep", "Separator",
choices = c(Semicolon = ";",
Comma = ",",
Tab = "\t",
Excel = ""),
selected = ","),
# Input: Select number of rows to display ----
radioButtons("disp", "Display",
choices = c(Head = "head",
All = "all"),
selected = "head"),
),
#column(7,dataTableOutput('dto')),
# Input: Select number of rows to display ----
# each item within the sidebar
# each table or output has to be on the same sidebarPanel or mainPanel
mainPanel(
DTOutput('contents')),
#plotOutput("plot")),
)
# next tab
),
tabPanel
(
"Depth Ranking Plot",
sidebarLayout
(
sidebarPanel
(
selectizeInput("elementInput", "Variable",
choices = unique(Data1$Element),
selected="", multiple =TRUE),
selectInput("select a age", label = "Age",choices = unique(Data1$Age),
selected="", multiple =TRUE),
helpText (strong("for multiple choices hold Strg button" )),
br(),
#dateRangeInput("dates", label = h3("Select depth range")),br(),,
numericRangeInput(inputId = "noui1", label = "Depth Range",
value = c(150, 400)), br(),
actionButton("action", label = "Proceed with select depth"),
br(),
# download selected data
h5 (strong("Download")),
downloadButton("downloadData", "Download brushed data"),
h5(strong("Brushed points appear here")),
tableOutput("data_brush")
),
# outputs
mainPanel(
plotOutput("depth", brush = brushOpts(id = "plot_brush", resetOnNew = FALSE,
fill = "red", stroke = "#036", opacity = 0.3)),
verbatimTextOutput("info"),
#fluidRow(
# left side actual dataset and right side the rows for datapoints selected by brush
# defined the width of each column and also some styling (bold & italics) using tags
#column(width = 5, tags$b(tags$i("Actual Dataset")), tableOutput("data")),
#column(width=5, tags$b(tags$i("Rows corresponding to datapoints under brush")), tableOutput("data_brush"))
),
)
# next tab
),
tabPanel(
"Univariate Data Description and Visualization",
sidebarLayout
(
sidebarPanel
(
selectizeInput("elementInput", "Choose a Variable",
choices = unique(Data1$Element),
selected="", multiple =TRUE),
selectizeInput("ageInput", "Choose a Age",
choices = unique(Data1$Age),
selected="", multiple =TRUE)),
sliderInput("slider", "Choose a Range", 300, 500,
value = c(300, 500), step = 10)),
selectizeInput("statinput", "Choose a Plot",
selected = "", choice =c ("Boxplot",
"Frequency Histogram" ,
"QQ Normal Plot",
"Jitter Boxplot")),
# output
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table")),
verbatimTextOutput("info")),
)
)
))
# Show a plot of the generated distribution
#mainPanel(
#column(width = 6,
#plotOutput("depth")))
##########################################################################
#tabsetPanel(type = "tabs",
# tabPanel("Plot", plotOutput("plot")),
# tabPanel("Summary", verbatimTextOutput("summary")))
#tabPanel("Table", tableOutput("table"))
# Define server logic to read selected file ----
server <- function(input, output) {
output$contents <- renderDT({
inFile <- input$file1
if(is.null(inFile))
return(NULL)
file.rename(inFile$datapath,
paste(inFile$datapath, ".xlsx", sep=""))
read_excel(paste(inFile$datapath, ".xlsx", sep=""), 1)
})
# Reactive expression with the data, in this case iris
#the data <- reactive(inFile)
#the extensions parameter coupled with the options list does the trick
# output$dto <- renderDataTable(thedata(), extensions = 'Buttons',
#options = list(dom = 'Bfrtip',
#buttons = c('copy', 'csv', 'excel', 'pdf', 'print'))
#)
output$plot <- renderPlot({
plot(Data1$Value, type=input$statinput)
})
output$summary <- renderPrint({
summary(Data1$Element)
})
output$depth <- renderPlot({
Data1%>%
select(Age, Depth, Element, Value)%>%
filter (Element %in% c("TOC", "TS", "S1", "S2", "S3", "Tmax", "HI", "OI"))%>%
#filter(Age %in% c("-Bartonian to Priabonian", "-Ypresian to Lutetian",
#"-Campanian", "-Turonian", "-Santonian", "Coniacian"))%>%
ggplot(aes(x= Depth, y= Value, color = Element, na.rm = TRUE))+
geom_line()+ geom_point()+
#scale_x_reverse()+
coord_flip()+
scale_x_reverse(limits = c(400, 100),
breaks = seq(400, 100, by = -50))+
facet_wrap(. ~ Element, scales = 'free_x', nrow = 1)+
scale_color_brewer(palette="Paired", guide = FALSE)+
#scale_x_discrete()
scale_y_continuous()+
labs(title = "Depth plot",
subtitle = "Predictive mean mapping\
Eratosthenes seamount (ODP Leg-160), Organic Measurments, N = 121",
caption = "Data source: Core 966-F, 967-A,E",
#x = "Ge [ppm]", y = expression(Fe[2]*O[3]),"[ppm]",
x= "Depth [m]",
#y = expression(Si*O[2] * "[%]"), x= "Depth [m]",
tag = "")+
theme_bw(base_size = 15)+
theme(axis.text.x=element_text(size=rel(0.5)))+
theme(axis.title.x=element_blank())
})
# brushedPoints returns the row of data under the brush
# brush information comes from ui to server using brushId and can be accessed using input$brushId
output$data_brush <- renderTable({
n = nrow(brushedPoints(Data1, brush = input$plot_brush)) # row count will be 0 when no selection made by the brush
if(n==0)
return()
else
brushedPoints(Data1, brush = input$plot_brush) # return rows
# argument allRows = TRUE can also be used
## It will add another column (selected_) to the actual dataset. True indicates that data point
# corresponding to that row was under the brush. False means data corresponding to that row wasn't selected by brush
})
}
shinyApp(ui = ui, server = server)
Vielleicht findet sich jemand, der mir bei der Verwirklichung des Projektes helfen könnte und ich bin über jede Hilfe und Hinweis dankbar!