Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何操作使用反应式表达式的呈现数据表?_R_Shiny_R Markdown_Reactive Programming - Fatal编程技术网

R 如何操作使用反应式表达式的呈现数据表?

R 如何操作使用反应式表达式的呈现数据表?,r,shiny,r-markdown,reactive-programming,R,Shiny,R Markdown,Reactive Programming,我不太会用闪亮的。下面的代码实际上是Rmarkdown文件的一部分,其中包含闪亮的编码 我在处理Shiny中的被动表达时遇到了一个问题。基本上,在调用反应式表达式之后,我可以渲染或绘制表达式。我不容易做的是在调用数据后对其进行操作 我已成功渲染并输出load\u table()。这只是告诉它在单击按钮时加载csv文件。见下面的代码: ```{r UI inputs} wellPanel( fileInput("dataset", label = "Select a .csv File to

我不太会用闪亮的。下面的代码实际上是Rmarkdown文件的一部分,其中包含闪亮的编码

我在处理Shiny中的被动表达时遇到了一个问题。基本上,在调用反应式表达式之后,我可以渲染或绘制表达式。我不容易做的是在调用数据后对其进行操作

我已成功渲染并输出
load\u table()
。这只是告诉它在单击按钮时加载csv文件。见下面的代码:

```{r UI inputs}
wellPanel(
  fileInput("dataset", label = "Select a .csv File to upload",
            accept=c("text/csv",
                     "text/comma-separated-values,text/plain",
                     ".csv")),

actionButton(inputId = "loadbutton", label = "Load Data")
)

dataTableOutput("df")

```

```{r Server Functions}
load_table <- eventReactive(input$loadbutton, {
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, it will be a data frame with 'name',
    # 'size', 'type', and 'datapath' columns. The 'datapath'
    # column will contain the local filenames where the data can
    # be found.
    inFile <- input$dataset

    if (is.null(inFile)){
      return(NULL)}
    else {
      read.csv(inFile$datapath)}
    })

output$df <- renderDataTable({
  load_table()
})
```
`{r UI输入}
井面板(
fileInput(“dataset”,label=“选择要上载的.csv文件”,
接受=c(“文本/csv”,
“文本/逗号分隔值,文本/普通”,
“.csv”),
actionButton(inputId=“loadbutton”,label=“Load Data”)
)
dataTableOutput(“df”)
```
```{r服务器功能}

load\u table
load\u table()
是一个可操作的反应式data.frame。e、 g.
load_table()$Year
将从data.frame中选择年份。@t我一定是做错了什么,因为我无法显示
load_table()$Year
。我添加了:
output$Year Try
load_table()[,“Year”]
。必须有一个返回数据帧或矩阵的表达式@谢谢你!这对我来说很有效,但我不得不扔掉逗号,这很奇怪,因为当我检查它的结构时,R说它是一个数据帧。无论如何,再次谢谢你。我现在可以用它来开发一个更复杂的ShinyApp。当你只选择一列时,BaseR在幕后简化了数据结构。如果选择多个列,它将保留dataframe结构,或者您可以包装
data.frame
以重新转换它。