R 闪亮的绘图出现在两个窗口中(绘图不显示)
我解决了我的问题。然而,我的代码有一个巨大的缺陷:当我运行应用程序时,Shining只显示复选框。在R-Studio中,它在弹出窗口中显示复选框,并在R-Studio-Viewer选项卡中显示绘图 我尝试将这两个元素放在R 闪亮的绘图出现在两个窗口中(绘图不显示),r,shiny,plotly,R,Shiny,Plotly,我解决了我的问题。然而,我的代码有一个巨大的缺陷:当我运行应用程序时,Shining只显示复选框。在R-Studio中,它在弹出窗口中显示复选框,并在R-Studio-Viewer选项卡中显示绘图 我尝试将这两个元素放在侧边栏布局-面板中。但是没有用。有什么办法可以让这一切顺利进行吗 library(shiny) library(plotly) library(dplyr) shinyApp( ui = fluidPage(sidebarLayout( sidebarPanel(c
侧边栏布局
-面板中。但是没有用。有什么办法可以让这一切顺利进行吗
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
})
}
)
库(闪亮)
图书馆(绘本)
图书馆(dplyr)
shinyApp(
ui=fluidPage(侧栏布局(
侧边栏面板(checkboxGroupInput(“Addtext”,“lines”,“c”(“跟踪0”,“跟踪1”),”),宽度=2),
主面板(plotOutput('plot1'),宽度=9)
)
),
服务器=函数(输入、输出){
输出$plot1=渲染图({
p%
添加_道(x=c(-1,0.4,2.5),y=c(2,0,-1),type='scatter',mode='lines')
如果(!为.null(输入$Addtext)){
if(“%input$Addtext中的跟踪0%”){
p%add_道(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(颜色='#000000',大小=10),
hoverinfo='skip',showlegend=FALSE)
}
if(“%input$Addtext中的跟踪1%”){
p%add_道(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(颜色='#000000',大小=10),
hoverinfo='skip',showlegend=FALSE)
}
}
P
})
}
)
使用plotly
软件包时,请使用plotlyOutput
和renderply
library(shiny)
library(plotly)
library(dplyr)
shinyApp(
ui = fluidPage(sidebarLayout(
sidebarPanel(checkboxGroupInput("Addtext", 'lines',c('trace 0','trace 1'),''),width = 2),
mainPanel(plotlyOutput('plot1'),width=9)
)
),
server = function(input, output) {
output$plot1 = renderPlotly({
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)
}
}
return(p)
})
}
)
库(闪亮)
图书馆(绘本)
图书馆(dplyr)
shinyApp(
ui=fluidPage(侧栏布局(
侧边栏面板(checkboxGroupInput(“Addtext”,“lines”,“c”(“跟踪0”,“跟踪1”),”),宽度=2),
主面板(plotlyOutput('plot1'),宽度=9)
)
),
服务器=函数(输入、输出){
输出$plot1=renderPlotly({
p%
添加_道(x=c(-1,0.4,2.5),y=c(2,0,-1),type='scatter',mode='lines')
如果(!为.null(输入$Addtext)){
if(“%input$Addtext中的跟踪0%”){
p%add_道(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(颜色='#000000',大小=10),
hoverinfo='skip',showlegend=FALSE)
}
if(“%input$Addtext中的跟踪1%”){
p%add_道(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(颜色='#000000',大小=10),
hoverinfo='skip',showlegend=FALSE)
}
}
返回(p)
})
}
)
再次感谢。不知何故,我不确定是否仍然支持
renderPlotly
。我猜不是所有的东西都在闪亮的备忘单上。plotly
和大多数其他JS
库都不受shinny
团队的支持,因此您只需阅读在if函数中出错的文档,字符串(例如'trace 0'
)需要放在第一位。然后才是输入$Addtext
。否则,无法显示这两个批注