R 通过Plotly在Shiny应用程序中绘制缺少的数据图表
下午好 我试图从ggplot2的经济学数据集中绘制一个简单的时间序列。应用程序加载并显示具有正确轴的图表,但不包括任何绘图数据。任何帮助都将不胜感激。最好的,乔R 通过Plotly在Shiny应用程序中绘制缺少的数据图表,r,shiny,plotly,R,Shiny,Plotly,下午好 我试图从ggplot2的经济学数据集中绘制一个简单的时间序列。应用程序加载并显示具有正确轴的图表,但不包括任何绘图数据。任何帮助都将不胜感激。最好的,乔 library(shiny) library(plotly) library(tidyverse) df <- economics datalst = colnames(df) ui <- pageWithSidebar( headerPanel("test"), sidebarPanel( selec
library(shiny)
library(plotly)
library(tidyverse)
df <- economics
datalst = colnames(df)
ui <- pageWithSidebar(
headerPanel("test"),
sidebarPanel(
selectInput(inputId = "x",
label = "Choose the x axis",
datalst),
selectInput(inputId = "y",
label = "Choose the y axis",
datalst, datalst[[2]])
),
mainPanel(
plotlyOutput("plot")
)
)
server <- function(input, output) {
dataset <- reactive({
df[, c(input$x, input$y)]
})
output$plot = renderPlotly({
plot_ly(dataset(), x = ~input$x, y = ~input$y,type = 'scatter', mode = 'lines')
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(绘本)
图书馆(tidyverse)
df这里的诀窍是避免非标准求值,因为input$x
和input$y
求值到字符串,而在您的示例中使用plotly
则需要在~”之后使用裸列名。您可以使用以下方法解决此问题,例如:
server plot\u ly(x=dataset()[[input$x]],y=dataset()[[input$y]],type='scatter',mode='lines')@ibusett,效果很好!非常感谢。很高兴它起到了作用,我现在也把它作为一个答案发布了,因为我认为它可以让其他人受益。