查看这些可能对您的案例有用的资源:
-
Plotly R 书 https://plotly-book.cpsievert.me/ by 卡森·西弗特 https://stackoverflow.com/users/1583084/carson第 3、4 和 6 章
- plotly代理函数解释 https://plot.ly/r/plotlyproxy/
这是帮助您入门的代码。您需要做一些调整轴标签的工作,但这应该不那么困难。
希望这可以帮助!
代码:
library("shiny")
library("plotly")
ui <- fluidPage(
selectInput("dataset", "Choose a dataset:", choices = c("rock", "mtcars")),
plotlyOutput("Plot1")
)
server <- function(input, output, session) {
dataSource <- reactive({switch(input$dataset,"rock" = rock,"mtcars" = mtcars)})
output$Plot1 <- renderPlotly({plot_ly(data = rock, x = ~area,
y =~peri, mode = 'markers', type = 'scatter')})
observeEvent(input$dataset, {
f <- list(
family = "Courier New, monospace",
size = 18,
color = "#7f7f7f"
)
x <- list(
title = "x Axis",
titlefont = f,
range = c(0, 1000)
)
y <- list(
title = "y Axis",
titlefont = f,
range = c(0, 100)
)
plotlyProxy("Plot1", session) %>%
plotlyProxyInvoke("addTraces", list(x = dataSource()[,1],
y = dataSource()[,2],
type = 'scatter',
mode = 'markers')) %>%
plotlyProxyInvoke("deleteTraces", list(as.integer(0))) %>%
plotlyProxyInvoke("relayout", list(xaxis = x, yaxis = y))
})
}
shinyApp(ui, server)