I have a problem with shinyjs hide() and show(). I use this to hide and show different data anyalysis that can be choosen from a side bar. If I do one part of my code it works fine but when I hide() and then do a different calculation it shows me the text part of the firt one again. Does anyone has any idea oder experienced similar things?
I expect my code to hide/delete the part I did not want to see anymore and just showing me the new analysis I choosed.
Thanks and best, Marina
Here´s my code from UI:
tabPanel(title="Datenanalyse",value="analysis",
includeMarkdown("../Texte/Mietpreise/Datenanalyse.md"),
fluidPage(
sidebarLayout(
sidebarPanel(
uiOutput("variables"),
selectInput("methods","Analysemethode",choices= c("Boxplot"="box","Balkendiagramm"="balken",
"Histogramm"="hist","Streudiagramm"="streu",
"Kreisdiagramm"="kreis",
"arithm. Mittel"="mw","N(%)"="anz","Regression"="reg"),
selected="box"),
actionButton("vorschau","Vorschau"),
actionButton("clear","Löschen"),
actionButton("fest","Festsetzen"),
hr(),
br(),
br(),
br(),
br(),
actionButton("zurueck3","Zurück"),
actionButton("hilfe3", "Hilfe"),
actionButton("weiter4","Weiter")
),
mainPanel(
textOutput("txt"),
textOutput("txt3"),
uiOutput("createvars"),
tableOutput("txt2"),
plotOutput("plot")
)
)
)
)
And here´s the part from server:
observeEvent(input$clear,{
shinyjs::hide("plot")
shinyjs::hide("txt")
shinyjs::hide("txt2")
shinyjs::hide("txt3")
shinyjs::hide("createvars")
})
observeEvent(input$vorschau,{
shinyjs::show("plot")
shinyjs::show("txt")
shinyjs::show("txt2")
shinyjs::show("createvars")
shinyjs::show("txt3")
})
observeEvent(input$vorschau,{
output$plot <- renderPlot({
if(input$methods =="box"){
if(length(input$variables==1)){
p <- boxplot(x = d()[input$variables],xlab=input$variables)
}
if(length(input$variables)>1){
p <- boxplot(x = d()[input$variables])
}
}
if(input$methods =="balken"){
p <- barplot(table(d()[input$variables]),xlab=input$variables)
}
if(input$methods =="hist"){
p <- hist(as.numeric(unlist(d()[input$variables])),xlab=input$variables, ylab="Anzahl", main="")
}
if(input$methods =="streu"){
p <- plot(d()[input$variables])
}
if(input$methods =="kreis"){
p <- pie(table(d()[input$variables]),main = input$variables)
}
})
output$txt <- renderText({
if(input$methods =="mw"){
paste0("Das arithmetische Mittel von ",input$variables," beträgt: ", round(mean(as.numeric(unlist(d()[input$variables]))),2))
}
})
output$txt2 <- renderTable({
if(input$methods =="anz"){
t<-data.frame(table(d()[input$variables]))
col_headings <- c(paste0(input$variables),"Freq")
colnames(t)<-col_headings
t
}
})
if(input$methods =="reg"){
output$txt3 <- renderText({
paste0("Geben Sie zuerst die Einflussgröße und dann die Zielgröße im Feld Variablenauswahl an.")
})
output$plot<-renderPlot({
lmodel <- lm(as.numeric(unlist(d()[input$variables][2]))~as.numeric(unlist(d()[input$variables][1])))
plot(d()[input$variables],xlab = names(d()[input$variables][1]),
ylab=names(d()[input$variables][2]), main= paste(names(d()[input$variables][2]),' =', round(coef(lmodel)[[2]],2), ' * ', names(d()[input$variables][1]), '+', round(coef(lmodel)[[1]],2)))
abline(lmodel)
})
}
})