i just new in Shiny and i have a problem in shiny. i have a plot but the plot not display in shiny. and no message error.this is the code...
UI
library(shiny)
ui = fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
),
mainPanel(
uiOutput("scatter")
))
)
server
library(shiny)
server = function(input, output) {
output$scatter <- renderUI({
datax <- matrix(c(1,2,3,4,5,6),6,1)
datay <- matrix(c(1,7,6,4,5,3),6,1)
titleplot<-"title"
summary <- "testing text"
pl <- plot(datax, datay, main = titleplot, xlab = "input$axis1", ylab = "input$axis2", pch=18, col="blue")
list(
pl,
summary
)
})
}
Actually you also can use uiOutput, and it is very useful sometimes, because you can create a user interface from the server side. This is the solution:
library(shiny)
ui = fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
),
mainPanel(
uiOutput("scatter")
))
)
server = function(input, output) {
output$scatter <- renderUI({
datax <- matrix(c(1,2,3,4,5,6),6,1)
datay <- matrix(c(1,7,6,4,5,3),6,1)
titleplot<-"title"
summary <- "testing text"
output$plot_test <- renderPlot({
pl <- plot(datax, datay, main = titleplot, xlab = "input$axis1", ylab = "input$axis2", pch=18, col="blue")
})
plotOutput("plot_test")
})
}
# Run the application
shinyApp(ui = ui, server = server)
Change your renderUI
function in server
to renderPlot
while uiOutput
to plotOutput
in ui
correspondingly.
library(shiny)
ui = fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
),
mainPanel(
plotOutput("scatter")
))
)
server = function(input, output) {
output$scatter <- renderPlot({
datax <- matrix(c(1,2,3,4,5,6),6,1)
datay <- matrix(c(1,7,6,4,5,3),6,1)
titleplot<-"title"
summary <- "testing text"
pl <- plot(datax, datay, main = titleplot, xlab = "input$axis1", ylab = "input$axis2", pch=18, col="blue")
list(
pl,
summary
)
})
}
shinyApp(ui, server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With