我对 R 还很陌生,我正在尝试组装一个 Flexdashboard,它从用户输入中获取 x 和 y 变量并返回这些值的图表。到目前为止,我可以在下面的代码中使用 ggplotly 生成所需的图表。
output$scatter <-renderPlotly({
cat('input$x=',input$x,'\n')
cat('input$y=',input$y,'\n')
p <- ggplot(Merged_data_frame_hcat, aes_string(x=input$x, y=input$y)) +
geom_point()+
theme_minimal(base_size = 14)
g <- ggplotly(p, source = 'source') %>%
layout(dragmode = 'lasso',
margin = list(l = 100),
font = list(family = 'Open Sans', size = 16))
})
Run Code Online (Sandbox Code Playgroud)
然而,我意识到使用 ggplotly,我的 x 轴的定义并不像我使用plot_ly 在仪表板外部绘制相同变量时那样定义。
有没有办法在 Flexdashboard 旁边使用plot_ly?到目前为止,我写了这个,但没有用。顺便说一句,我在这里使用 noquote 因为plot_ly 没有很好地接受作为字符串的输入名称
output$scatter <-renderPlotly({
cat('input$x=',input$x,'\n')
cat('input$y=',input$y,'\n')
if (length(input$y) == 2){
x1 = noquote(input$x)
y1 =noquote(input$y[1])
y2 = noquote(input$y[2])
plot_ly(Merged_data_frame_hcat)%>%
add_lines(x= ~x1,y =~y1, …Run Code Online (Sandbox Code Playgroud)