【发布时间】:2017-09-13 15:41:25
【问题描述】:
我解决了我的own question here。但是我的代码有一个很大的缺陷:当我运行应用程序时,Shiny 只显示复选框。在 R-Studio 中,它显示了弹出窗口中的复选框和 R-Studio-Viewer 选项卡中的绘图。
我尝试将这两个元素放在sidebarLayout-Panel 中。但无济于事。有什么办法可以使这项工作?
library(shiny)
library(plotly)
library(dplyr)
shinyApp(
ui = fluidPage(sidebarLayout(
sidebarPanel(checkboxGroupInput("Addtext", 'lines',c('trace 0','trace 1'),''),width = 2),
mainPanel(plotOutput('plot1'),width=9)
)
),
server = function(input, output) {
output$plot1 = renderPlot({
p<-plot_ly(x = c( -2, 0, 1.5 ),y = c( -2, 1, 2.2), type = 'scatter' ,mode = 'lines') %>%
add_trace(x=c(-1,0.4,2.5),y=c(2, 0, -1),type='scatter',mode='lines')
if(!is.null(input$Addtext)){
if('trace 0'%in%input$Addtext){
p<- p %>% add_trace(x=c( -2, 0, 1.5 ),y= c( -2, 1, 2.2),type='scatter',mode='text',
text=c('(-2,-2)','(0,1)','(1.5,2.2)'),
textposition='right',textfont = list(color = '#000000', size = 10),
hoverinfo='skip',showlegend=FALSE)
}
if('trace 1'%in%input$Addtext){
p<- p %>% add_trace(x=c( -1, 0.4, 2.5 ),y= c( 2, 0, -1),type='scatter',mode='text',
text=c('(-1,2)','(0.4,0)','(2.5,-1)'),
textposition='right',textfont = list(color = '#000000', size = 10),
hoverinfo='skip',showlegend=FALSE)
}
}
p
})
}
)
【问题讨论】: