A prolb is some mistake in the name between server.randui.r
server.r
output$variableOutput = renderUI({
selectInput("VariableInput",
"Variable auswählen",
choices = colnames(training)[-1] ,
selected = 2)
<select id="VariableInput" ...>
<option value="X13_K"></option>
</select>
uiOutput("variableOutput"),
. , output$variableOutput.
, condition = "input.VariableOutput == 'X13_k'" , VariableInput
selectInput("VariableInput",
"Variable auswählen",
choices = colnames(training)[-1] ,
selected = 2)
condition = "input.VariableInput == 'X13_k'"
, VariableInput VariableOutput by VariableSelection` - .
:
library(shiny)
library(ggplot2)
training=iris
names(training)[5] <- c("X13")
server = function(input,output){
output$variableOutput = renderUI({
selectInput("VariableInput",
"Variable auswählen",
choices = colnames(training)[-1] ,
selected = 2)
})
plot_data = reactive({frame = as.data.frame(cbind(training[,1],
training[,input$VariableInput]))
frame[,1] = as.logical(frame[,1])
return(frame)
})
mean_data = reactive({data.frame(flag = c("2","1"),
data = c(weighted.mean(training[,input$VariableInput][training$flag==1],
training$weight[training$flag==1]),
weighted.mean(training[,input$VariableInput][training$flag==0],
training$weight[training$flag==0])))
})
output$coolPlot_3 = renderPlot({
if (is.null(input$VariableInput)) {
return(NULL)
}
numb_classes = length(levels(training[,input$VariableInput]))
row_names = levels(training[,input$VariableInput])
plot_data_2 = data.frame(klassen = character(numb_classes),
index = numeric(numb_classes),
stringsAsFactors = FALSE)
for (j in 1:numb_classes){
count_class_non_goal = count(subset(training[,input$VariableInput],
training[,input$VariableInput] == row_names[j] & training[,"flag"] == FALSE))
count_all_non_goal = count(training[training$flag == FALSE,input$VariableInput])
percent_non_goal = count_class_non_goal[,2]/(sum(count_all_non_goal[,2])/100)
count_class_goal = count(subset(training[,input$VariableInput],
training[,input$VariableInput] == row_names[j] & training[,"flag"] == TRUE))
count_all_goal = count(training[training$flag == TRUE,input$VariableInput])
percent_goal = count_class_goal[,2]/(sum(count_all_goal[,2])/100)
plot_data_2[,1][j] = row_names[j]
plot_data_2[,2][j] = round((percent_goal/percent_non_goal*100)-100,
digits =2)
}
ggplot(data = plot_data_2) +
geom_bar(aes(y = index,
x = klassen),
stat= "identity")+
coord_flip()+
theme(legend.position = "none",
axis.title.x = element_text(size=15,
face = "bold"),
axis.text.y = element_text(size=12),
axis.text.x = element_text(size=12),
axis.title.y = element_text(size=15,
face = "bold"))+
labs(x = paste(input$VariableInput),
y = "Index")
})
output$coolPlot = renderPlot({
if (is.null(input$VariableInput)) {
return(NULL)
}
ggplot(data = plot_data()) +
geom_boxplot(aes(x=V1,
y=V2,
fill=V1),
outlier.shape = NA) +
guides(fill=FALSE)+
scale_x_discrete(labels=c("Nicht-Ziel", "Ziel")) +
coord_cartesian(ylim = c(min(plot_data()[,"V2"]),
quantile(plot_data()[,"V2"])[4] + IQR(plot_data()[,"V2"],
na.rm = TRUE, type = 7)*1.9)) +
stat_boxplot(aes(x=V1,
y=V2,
fill=V1),
geom ='errorbar') +
theme(axis.title.x = element_text(size=15,
face = "bold"),
axis.text.y = element_text(size=12),
axis.text.x = element_text(size=12),
axis.title.y = element_text(size=15,
face = "bold"))+
labs(x = paste(input$VariableInput),
y = "Ausprägung der Variable")
})
output$coolPlot_2 = renderPlot({
if (is.null(input$VariableInput)) {
return(NULL)
}
ggplot(data = plot_data(),
aes(x=V2,
fill=V1)) + geom_density(alpha=.3)+
geom_vline(data=mean_data(),
aes(colour=flag,
xintercept=data),
linetype="dashed", size=1)+
scale_fill_discrete(name = "Gruppen",
labels=c("Nicht-Ziel",
"Ziel"))+
theme(axis.title.x = element_text(size=15,
face = "bold"),
axis.text.y = element_text(size=12),
axis.text.x = element_text(size=12),
axis.title.y = element_text(size=15,
face = "bold"))+
labs(x = paste(input$VariableInput),
y = "Density")
})
output$coolTable = renderDataTable({
training
})
}
library(shiny)
ui = fluidPage(
titlePanel("Data Visualization"),
sidebarLayout(
sidebarPanel(
uiOutput("variableOutput"),
uiOutput("text1Output")
),
mainPanel(
conditionalPanel(
"input.VariableInput != 'X13'",
plotOutput("coolPlot")),
# textInput("bla","blub",input.variableOutput),
br(),
br(),
conditionalPanel(
condition = "input.VariableInput != 'X13'",
plotOutput("coolPlot_2")),
conditionalPanel(
condition = "input.VariableInput == 'X13'",
plotOutput("coolPlot_3")),
br(),
br(),
dataTableOutput(
"coolTable"
)
)
)
)