I've been thinking if there's an answer to the question.
So i have this code in server.R
desc <- reactive({
for (i in 1:input$txt1){
print(paste("Cluster ke", i))
clust <- ensemble()
newdata <- clust[which(clust$Cluster==i), 1]
print(paste(newdata))
barm <- vector("numeric")
x <- ncol(clust)-2
for (j in 2:x){
datdesc <- clust[which(clust$Cluster==i), j]
m <- mean(datdesc)
colnam <- colnames(clust[j])
print(paste("Rata-rata produktivitas", colnam,":", m))
for(k in j-1){
barm[k] <- m
}
}
print(paste(barm))
barplot(barm)
}
})
output$desc <- renderPrint({
desc()
})
And this in the ui
conditionalPanel(condition="input.choice==3", verbatimTextOutput("desc"))
So far, i can get all the output i wanted, the descriptive text and the bar plot. But, the bar plot is appears at the R console instead on the browser.
Is there any way to make the text and barplot show up at the same page?
Can i use other function of renderPrint or verbatimTextOutput that possibly can do that?
Or any other ways?
I've been thinking some solution to this, like dividing the desc() so it has two outputs, text and barplot. But if there's a way to make it in one go, I'm very much want to learn that way.
Sure, it's common to have many different output types. Please see the Shiny gallery for more examples.
Based on the code you provided and a template:
UI.R
bootstrapPage(
selectInput(
"choice", "txt1 - descriptive text?",
c(my_text = "my_text",
your_text = "your_text")),
selectInput(inputId = "n_breaks",
label = "Number of bins in histogram (approximate):",
choices = c(10, 20, 35, 50),
selected = 20),
checkboxInput(inputId = "individual_obs",
label = strong("Show individual observations"),
value = FALSE),
checkboxInput(inputId = "density",
label = strong("Show density estimate"),
value = FALSE),
plotOutput(outputId = "main_plot", height = "300px"),
conditionalPanel(condition="input.choice=='my_text'", verbatimTextOutput("desc"))
)
Server.R
function(input, output) {
desc <- reactive({
"some text goes here, I guess!"
})
output$desc <- renderPrint({
desc()
})
output$main_plot <- renderPlot({
hist(faithful$eruptions,
probability = TRUE,
breaks = as.numeric(input$n_breaks),
xlab = "Pandjie Soerja",
main = "Pandjie Soerja")
if (input$individual_obs) {
rug(faithful$eruptions)
}
if (input$density) {
dens <- density(faithful$eruptions,
adjust = input$bw_adjust)
lines(dens, col = "blue")
}
})
}