Jump to content

File:Plotly shiny 3d.png

From 太極
Revision as of 13:51, 19 February 2026 by Brb (talk | contribs) (<syntaxhighlight lang='r'> # method 3: install.packages(c("shiny","plotly")) library(shiny) library(plotly) ui <- fluidPage( titlePanel("3D scatter (plotly)"), sidebarLayout( sidebarPanel( selectInput("x", "X axis", choices = names(iris), selected = "Sepal.Length"), selectInput("y", "Y axis", choices = names(iris), selected = "Sepal.Width"), selectInput("z", "Z axis", choices = names(iris), selected = "Petal.Length") ), mainPanel(plotlyOutput("plot3d")) )...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Original file (1,658 × 906 pixels, file size: 135 KB, MIME type: image/png)

Summary

# method 3: install.packages(c("shiny","plotly"))
library(shiny)
library(plotly)

ui <- fluidPage(
  titlePanel("3D scatter (plotly)"),
  sidebarLayout(
    sidebarPanel(
      selectInput("x", "X axis", choices = names(iris), selected = "Sepal.Length"),
      selectInput("y", "Y axis", choices = names(iris), selected = "Sepal.Width"),
      selectInput("z", "Z axis", choices = names(iris), selected = "Petal.Length")
    ),
    mainPanel(plotlyOutput("plot3d"))
  )
)

server <- function(input, output, session) {
  output$plot3d <- renderPlotly({
    plot_ly(
      data = iris,
      x = as.formula(paste0("~", input$x)),
      y = as.formula(paste0("~", input$y)),
      z = as.formula(paste0("~", input$z)),
      color = ~Species, type = "scatter3d", mode = "markers",
      marker = list(size = 5)
    ) %>% layout(scene = list(xaxis=list(title=input$x), yaxis=list(title=input$y), zaxis=list(title=input$z)))
  })
}

shinyApp(ui, server)

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current13:51, 19 February 2026Thumbnail for version as of 13:51, 19 February 20261,658 × 906 (135 KB)Brb (talk | contribs)<syntaxhighlight lang='r'> # method 3: install.packages(c("shiny","plotly")) library(shiny) library(plotly) ui <- fluidPage( titlePanel("3D scatter (plotly)"), sidebarLayout( sidebarPanel( selectInput("x", "X axis", choices = names(iris), selected = "Sepal.Length"), selectInput("y", "Y axis", choices = names(iris), selected = "Sepal.Width"), selectInput("z", "Z axis", choices = names(iris), selected = "Petal.Length") ), mainPanel(plotlyOutput("plot3d")) )...

The following page uses this file: