如何从选择性输入中选择反应参数?

时间:2015-09-15 19:56:27

标签: r dygraphs shiny

我有一个选择框输入,它根据加载的.csv文件的列名进行更改。这就是我的observeEvent函数所做的。

当我在server.R中绘制输出时,我遇到了麻烦,因为我不确定如何制作反应参数以将SelectizeInput的输出转换为从renderDygraph中选择的列选择框。有没有人知道我应该在SelectizeInput输出中添加哪些内容来绘制我从ui.R选择的频道?

这是我的代码:

shinyUI(fluidPage( # Application title titlePanel("Graph"), fluidRow( column(6, wellPanel(` selectInput("dataSelection1", label = "Choose a File", choices = c("File1")), selectizeInput("channel1", label = "Choose a Channel", choices = NULL))), column(12, dygraphOutput("Graph") ) ) ) )

server.R

shinyServer(function(input, output, session) { dataSource1 <- reactive({ switch(input$dataSelection1, "File1" = File1) }) observeEvent(input$dataSelection1, { updateSelectizeInput(session, 'channel1', choices = names(dataSource1())) }) output$TempRise <- renderDygraph({ component <- switch(input$channel1, **'WHAT TO PUT IN HERE?'**) dygraph(component, main = "Data Graph") %>% dyRangeSelector() %>% dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2")) }) })

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            return new Configuration().configure().buildSessionFactory(
                new StandardServiceRegistryBuilder().build() );
        }
        catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}

1 个答案:

答案 0 :(得分:1)

我不认为您可以使用切换声明,因为您事先并不知道将其等同于什么,但我会这样做:

shinyServer(function(input, output, session) {

dataSource1 <- reactive({
    switch(input$dataSelection1,
            "File1" = File1)
        })

observeEvent(input$dataSelection1, { 
    updateSelectizeInput(session, 'channel1', choices = names(dataSource1())) 

})

output$TempRise <- renderDygraph({
        data <- dataSource1()
        selected_input <- input$channel1
        component <- data[, selected_input]

        dygraph(component, main = "Data Graph") %>%
          dyRangeSelector() %>%
          dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2"))

  })

 })