nachdem mir beim letzten Shiny Problem excellent geholfen wurde, wollte ich nochmal um Unterstützung bitten. Meine Idee ist, dass ich in Shiny mittels des Package corrmat ein Anwendung schreiben wollte. in dem der Benutzer sich die Matrix selbst zusammen stellen kann. Soll heißen, der Benutzer kann sich verschiedene Elmente aus dem Datensatz heraus suchen und sich hierfür die Matrix anzeigen lassen.
Beim implementieren in Shiny wird kein Fehler angezeigt! Aber der Plot erscheint einfach nicht. Verflixt! Kann mir vllt. jemand helfen und mir aufzeigen wo der "Hase im Pfeffer" liegt?
Die zweite Frage, betrifft die Auswahl. Ich habe immer noch nicht verstanden was der Unterschied zwischen "eventReactive" und/oder "observe" ist. Wahrscheinlich muss ich das hier anwenden um zum gewünschten Ergebnis zzu kommen?
Hier erstmal mein Ansatz:
Code: Alles auswählen
library(shiny)
library(shinyWidgets)
library(tidyverse)
library(plotly)
set.seed(1234)
A <- tibble (
Horizon = ("Horizon A"),
Depth = seq(0, 2.6, 0.2),
Element_1 = abs(round(rnorm(14), 2)),
Element_2 = abs(round(rnorm(14), 2)),
Element_3 = abs(round(rnorm(14), 2)),
Element_4 = abs(round(rnorm(14), 2)),
Element_5 = abs(round(rnorm(14), 2)),
Element_6 = abs(round(rnorm(14), 2)),
Element_7 = abs(round(rnorm(14), 2)),
Element_8 = abs(round(rnorm(14), 2)),
Element_9 = abs(round(rnorm(14), 2)),
Element_10 = abs(round(rnorm(14), 2))
)
B <- tibble (
Horizon = ("Horizon B"),
Depth = seq(2.8, 43.8, 0.33),
Element_1 = abs(round(rnorm(125), 2)),
Element_2 = abs(round(rnorm(125), 2)),
Element_3 = abs(round(rnorm(125), 2)),
Element_4 = abs(round(rnorm(125), 2)),
Element_5 = abs(round(rnorm(125), 2)),
Element_6 = abs(round(rnorm(125), 2)),
Element_7 = abs(round(rnorm(125), 2)),
Element_8 = abs(round(rnorm(125), 2)),
Element_9 = abs(round(rnorm(125), 2)),
Element_10 = abs(round(rnorm(125), 2))
)
C <- tibble (
Horizon = ("Horizon C"),
Depth = seq(44, 50, 0.6),
Element_1 = abs(round(rnorm(11), 2)),
Element_2 = abs(round(rnorm(11), 2)),
Element_3 = abs(round(rnorm(11), 2)),
Element_4 = abs(round(rnorm(11), 2)),
Element_5 = abs(round(rnorm(11), 2)),
Element_6 = abs(round(rnorm(11), 2)),
Element_7 = abs(round(rnorm(11), 2)),
Element_8 = abs(round(rnorm(11), 2)),
Element_9 = abs(round(rnorm(11), 2)),
Element_10 = abs(round(rnorm(11), 2))
)
Analyse.corr = rbind (A, B, C)
Analyse.corrl = Analyse.corr%>%
pivot_longer(
cols = Element_1: Element_10,
names_to = "Element",
values_to = "Values")
# Scatter Plot
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
# Korrelmatrix
pickerInput(
inputId = "corr",
label = "Correlmatrix",
choices = list(
Main = colnames(Analyse.corr) [c(3:6)],
Minor = colnames(Analyse.corr) [c(7:10)]),
multiple = TRUE,
options = pickerOptions(
actionsBox = TRUE,
title = "Please select at least 4 item",
header = "Main & Minor Elements")),
br(),
pickerInput(
inputId = "lithcor",
label = "Horizon",
choices = unique(Analyse.corr$Horizon),
selected = Analyse.corr$Horizon [1],
multiple = TRUE,
options = list("max-options" = 1,
"max-options-text" = "No more!")),
br(),
selectInput("type", "Correlation Type", selected = NULL,
choices = c("parametric", "nonparametric"), multiple = FALSE),
br(),
selectInput("p", "Choose a p-value", selected = NULL,
choices = c("0.01", "0.05"), multiple = FALSE),
),
# end sidebar panel
mainPanel(
tabsetPanel(type = "tab",
tabPanel("Korrelmatrix", plotOutput("cormat"))
))
))
# end main panel
server <- function(input, output, session) {
# correl matrix
#filter
reactivecorrel <- reactive({
Analyse.corr%>%
filter(Horizon %in% input$lithcor) %>%
select(-Horizon, -Depth, input$corr) # entfernt Horizont & Tiefe für Matrix zum Schluss
}) # bleiben nur noch numerische Werte übrig --> sollte eigentlich jetzt die Matrix sein (?)
# correlogram
output$cormat <- renderPlot({
plot <- ggstatsplot::ggcorrmat(
reactivecorrel (),
type = input$type, # parametric for Pearson, nonparametric for Spearman's correlation
sig.level = input$p,
#output = "p", will return the p-value matrix
hc.order = TRUE,
matrix.type = "upper", # Character, "upper", # (default), "lower", or "full", display full matrix, lower triangular or upper triangular matrix.
outline.col = "white",
title = "Correl matrix",
subtitle = "Subunit: ",
colors = c("darkred", "white", "steelblue") # change default colors
)
})
}
shinyApp(ui, server)
Vielen Dank für Eure Zeit & Hilfe,
retep