我怎样才能在 shiny 中包含一个 plotly violinplot?

How can I include a plotly violinplot in shiny?

如何在 shiny 中包含后面的小提琴情节?

library(plotly)
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv")

fig <- df %>%
  plot_ly( x = ~day, y = ~total_bill,
    split = ~day,type = 'violin',
    box = list(visible = T),
    meanline = list( visible = T)
  ) 

fig <- fig %>%
  layout( xaxis = list(title = "Day"),
    yaxis = list( title = "Total Bill",zeroline = F
    )
  )

fig

复制代码:

用户界面和服务器:

shinyUI(
  dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(),))        
# Server ------------------------------------------------------------------  
shinyServer(function(input, output){
})

通过renderPlotly(服务器)和plotlyOutput(ui):

library(shiny)
library(plotly)

DF <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv")

ui <- fluidPage(plotlyOutput("myplot"))

server <- function(input, output, session) {
  output$myplot <- renderPlotly({
    fig <- DF %>%
      plot_ly(
        x = ~ day,
        y = ~ total_bill,
        split = ~ day,
        type = 'violin',
        box = list(visible = T),
        meanline = list(visible = T)
      )
    
    fig <- fig %>%
      layout(
        xaxis = list(title = "Day"),
        yaxis = list(title = "Total Bill", zeroline = F)
      )
    
    fig
  })
}

shinyApp(ui, server)