(Shiny R)如何在UI中动态生成多个输出?

时间:2017-11-15 15:24:04

标签: r shiny shiny-server

我想根据数据渲染不同数量的图。我可以从ui访问数据,根据数据动态生成多个plotOutput调用吗?

例如,如果我们有这个代码:

shinyApp(
  ui <- fluidPage(
    lapply(WHAT I WANT TO ACCESS, function(patient) {
      fluidRow(column(1, tags$p(patient)), 
               column(11, lapply(unique(newDT[pat == patient]$clinic), 
                  function(clinic){
                    fluidRow(column(1, tags$p(clinic)),
                             column(10, plotOutput(outputId = paste(patient, clinic), height = "100%")))
                  })))

    })
  ),

  server <- function(input, output) {

    newDT2 <- reactive({
      newDT[dx.x == input$dx]
    })

    #WHAT I WANT TO ACCESS IN UI
    pats <- unique(newDT2()$pat)

    x <-reactive({max(newDT2()$dat) +0.5})
    #observe({print(x())})

    PLOT 
    })
      }
    })
    }
  }
  )

但是,我无法在服务器中访问ui中的数据框。有没有什么好处?

TIA!

1 个答案:

答案 0 :(得分:0)

您需要对import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; import javafx.geometry.Insets; import javafx.scene.control.TextField; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.Priority; import javafx.scene.layout.Pane; import javafx.scene.control.Label; public class Microwave extends Application { @Override public void start(Stage primaryStage) { Pane root = new Pane(); GridPane gPane1 = new GridPane(); GridPane gPane2 = new GridPane(); TextField time = new TextField("Time to be displayed here"); Label food = new Label("Place food here"); Button start_button = new Button("Start"); Button stop_button = new Button("Stop"); Button button_0 = new Button("0"); Button button_1 = new Button("1"); Button button_2 = new Button("2"); Button button_3 = new Button("3"); Button button_4 = new Button("4"); Button button_5 = new Button("5"); Button button_6 = new Button("6"); Button button_7 = new Button("7"); Button button_8 = new Button("8"); Button button_9 = new Button("9"); gPane1.add(start_button, 1, 3); gPane1.add(stop_button, 2, 3); gPane1.add(button_0, 0, 3); gPane1.add(button_1, 0, 0); gPane1.add(button_2, 1, 0); gPane1.add(button_3, 2, 0); gPane1.add(button_4, 0, 1); gPane1.add(button_5, 1, 1); gPane1.add(button_6, 2, 1); gPane1.add(button_7, 0, 2); gPane1.add(button_8, 1, 2); gPane1.add(button_9, 2, 2); gPane2.add(time,0,0); root.getChildren().addAll(gPane1,gPane2,food); Scene scene = new Scene(root,200,50); primaryStage.setTitle("Microwave Oven"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } 中的所有数据进行处理,然后将输出返回到server

在您的示例中,您可以在ui来电中将lapply来电置于服务器中,并将renderUI放在uiOutput的位置。

这是我的一个闪亮的应用程序的一个例子。

在服务器中:

ui

在ui中:

    # dynamically creates a numeric input for each activity in the activities table
    # for the PAL helper panel
    output$activityList <- renderUI({
        act <- split(as.character(activities[order(activities$Sort, activities$Activity), 
                                             "Activity"]), 
                     cut2(1:nrow(activities), g=3))
        div(class = "sidebyside", 
            fluidRow(column(4,lapply(as.character(act[[1]]), 
                           function(x) {numericInput(x,x, value = 0, step=0.5, min = 0)})),
                     column(4,lapply(as.character(act[[2]]), 
                           function(x) {numericInput(x,x, value = 0, step=0.5, min = 0)})),
                     column(4,lapply(as.character(act[[3]]), 
                           function(x) {numericInput(x,x, value = 0, step=0.5, min = 0)}))
                     )
        )

})