代码之家  ›  专栏  ›  技术社区  ›  Mikz

闪亮,从情节中获取细节

  •  0
  • Mikz  · 技术社区  · 7 年前

    我已经开发了一个应用程序,我正在生成绘图。我能够渲染绘图并下载,没有任何问题。

    当我将光标移动到点上时,我想获得图表中点的详细信息。通过搜索,我不确定是否可以在Shiny中获得此信息。

    任何帮助都会很好。

    下面是我使用过的代码。

    UI代码:

    tabItem(tabName = "models2",
            fluidPage(
              fluidRow(
                infoBoxOutput("overview")
              ),
              fluidRow(
                actionButton("result1","Generate Result"),
                downloadButton('downloadPlot','Download Plot'),
                plotOutput("plot3")
              )
            ))
    

    服务器代码

    server <- function(input,output){
    output$claim_overview <- renderValueBox({
        valueBox(
          paste("91")," Overview",icon=icon("hourglass"),
          color="green"
        )
      })
      data<-  reactiveValues()
      observeEvent(input$result1,{
    
        data$plot <-   ggplot(data=timedata, aes(x=dat1, y=yes, group=3))+ 
          geom_point(shape=1)+
          coord_cartesian(xlim=c(dat1_xlowlim,dat1_xhighlim))+
          labs(title="Prediction Probability",x="Reg.Date",y="True probability")  
      })
      output$plot3  <- renderPlot({ data$plot   })
    
      output$downloadPlot <- downloadHandler(
        filename = function()
        {paste("input$plot3",'.png',sep='')
        },
        content = function(file){
          ggsave(file,plot = data$plot)
    
        }
      )
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   OldStudent    7 年前

    您可以使用 brush 选项或 hover 选项从绘图中获取任何信息。

    鼠标悬停示例:

    df<- table(rpois(100, 5))
    ui <- fluidPage(
        mainPanel(
          plotOutput(outputId = "scatterplot", hover = "plot_hover"),
          verbatimTextOutput(outputId = "dftable"),
          br()
        )
      )    
    server <- function(input, output) {
    
      output$scatterplot <- renderPlot({
        plot(df, type = "h", col = "red", lwd = 10)
      })
    
      output$dftable <- renderPrint({
        paste(input$plot_hover)
      })
    }
    
    shinyApp(ui = ui, server = server)