Rails从ajax调用渲染视图(Rails Rendering view from ajax call)
我正在尝试使用ajax将params发送到控制器后呈现视图。 由于项目结构,我不得不走这条路线但是控制台返回:
Started POST "/rate" for 127.0.0.1 at 2016-02-17 19:49:42 -0500 Processing by PageController#yourrate as */* Rendered page/yourrate.html.erb within layouts/application (0.5ms) Rendered Shared_Templates/_navbar.html.erb (0.5ms) Rendered Shared_Templates/_footer.html.erb (0.0ms) Completed 200 OK in 188ms (Views: 187.1ms | ActiveRecord: 0.0ms)
我的ajax电话是:
$.ajax({ url:"rate", type: "post", data: "start=" + start + "&finish=" + finish + "&duration=" + duration + "&distance=" + distance, success: function(){ alert("Saved Successfully, distance: " + distance); //just for testing purposes. }, error:function(){ alert("Error"); } });
并且我的控制器具有属性,其中params被分配给我正在传递的。
I'm trying to render a view after sending params to the controller using ajax. I had to go this route due to the project structure but console returns:
Started POST "/rate" for 127.0.0.1 at 2016-02-17 19:49:42 -0500 Processing by PageController#yourrate as */* Rendered page/yourrate.html.erb within layouts/application (0.5ms) Rendered Shared_Templates/_navbar.html.erb (0.5ms) Rendered Shared_Templates/_footer.html.erb (0.0ms) Completed 200 OK in 188ms (Views: 187.1ms | ActiveRecord: 0.0ms)
and my ajax call is:
$.ajax({ url:"rate", type: "post", data: "start=" + start + "&finish=" + finish + "&duration=" + duration + "&distance=" + distance, success: function(){ alert("Saved Successfully, distance: " + distance); //just for testing purposes. }, error:function(){ alert("Error"); } });
and my controller has attributes with params being assigned to them that i'm passing.
原文:https://stackoverflow.com/questions/35470894
最满意答案
嗨,当你过滤
data.frame
使用%in%
而不是==
因为你比较的两个矢量不具有相同的长度,例如:df1 <- reactive({ df[df$OperatingUnit %in% input$check1 & df$indicator %in% input$check2, ] })
对于第二个“全选”按钮,如果您希望在单击它时发生某些事情,则必须在您的服务器中放置一个
observeEvent
:observeEvent(input$all1, { if (is.null(input$check2)) { updateCheckboxGroupInput( session = session, inputId = "check2", selected = paste(indi) ) } else { updateCheckboxGroupInput( session = session, inputId = "check2", selected = "" ) } })
Hi when you filter your
data.frame
use%in%
instead of==
because the two vectors you compare don't have the same length, e.g. :df1 <- reactive({ df[df$OperatingUnit %in% input$check1 & df$indicator %in% input$check2, ] })
For the second "select all" button you have to put an
observeEvent
in your server if you want that something happen if you click on it :observeEvent(input$all1, { if (is.null(input$check2)) { updateCheckboxGroupInput( session = session, inputId = "check2", selected = paste(indi) ) } else { updateCheckboxGroupInput( session = session, inputId = "check2", selected = "" ) } })
相关问答
更多-
您可以将Group B选择放在列表中以获得所需的输出: selectInput("test", "I am test", choices = list("Group A" = c("a", "b", "c"), "Group B" = list("d"))) You can put your Group B choice in a list to get the output you want: selectInput("test", "I am test", choices = list("Group ...
-
有多种方法可以做到这一点,这里有一个: library(shiny) server <- shinyServer(function(input, output) { NULL }) ui <- shinyUI( pageWithSidebar( headerPanel("side-by-side"), sidebarPanel( fluidRow( tags$head( tags$style(type="text/css", "label.c ...
-
在Shiny中的selectInput之后过滤sliderInput的数据集?(Filter dataset for sliderInput after selectInput in Shiny?)[2022-04-15]
试试这个,它的优势在于,因为Shiny很聪明,会缓存data()的输出,这样即使你多次调用它,也只会被评估一次。 library(DT) library(data.table) ui <- bootstrapPage( sidebarLayout( sidebarPanel( selectInput(inputId = "conf", label = "Choose a conference", choices ... -
更新R Shiny中动态创建的selectInput框的选项(Updating choices for dynamically-created selectInput boxes in R Shiny)[2022-05-14]
首先,我为函数newNode和createSliceBox添加了一个新的参数choices 。 newNode <- function(id, parentId, choices = NULL) { ... createSliceBox(id, parentId, choices) ... } createSliceBox <- function(id, parentId, choices) { .. ... -
如果你没有找到更好的解决方案,强制css( shiny-split-layout overflow )值应该有所帮助。 library(shiny) library(shinydashboard) ui <- dashboardPage( dashboardHeader(), dashboardSidebar( tags$head(tags$style(HTML('.shiny-split-layout>div {overflow:visible}'))) ), dashboardB ...
-
看起来当前的行为触发了退格上的事件,但输入值保持不变。 这种行为实际上可能是更新JavaScript函数Shiny.onInputChange时发生的意外更改。 shinys github网站上的新闻声称版本1.1下的内容如下。 新功能 [...] 对(未记录但广泛使用的)JavaScript函数Shiny.onInputChange(name, value)进行了两处更改。 首先,我们将函数名称更改为Shiny.setInputValue (但不要担心 - 旧函数名称将继续工作)。 其次, 到目前为止 , ...
-
SelectInput in Shiny(SelectInput in Shiny)[2023-10-01]
虽然我无法复制您的数据集,因为我不知道臭氧来自哪里,但我认为您的问题是您不是指这样的“被动”对象: stat_state() 一旦你创建了一个被动对象,除了无效值和输入$变量之外,你需要在变量的末尾用'()'来引用它。 下面是使用一些不同数据集的代码的示例。 希望这可以帮助。 require(shiny) ui <- fluidPage(pageWithSidebar( headerPanel("Population"), sidebarPanel( h3('State'),select ... -
如何从闪亮的selectInput()函数中绘制选定的输入?(How to plot selected input from selectInput() function in shiny?)[2022-05-04]
找到解决方案 server <- function(input, output) { partA = NULL partB = NULL makeReactiveBinding("partA") makeReactiveBinding("partB") observeEvent(input$categoryVisu, { partA<<-input$categoryVisu partA<<-as.character(partA) }) observeEv ... -
这是一个如何做的例子: library(shiny) ui<-fluidPage( titlePanel(title = "Prueba"), sidebarLayout( sidebarPanel( fileInput('file1', 'Cargar archivo', accept = c( 'text/csv', 'text/comma-separated-values ...
-
嗨,当你过滤data.frame使用%in%而不是==因为你比较的两个矢量不具有相同的长度,例如: df1 <- reactive({ df[df$OperatingUnit %in% input$check1 & df$indicator %in% input$check2, ] }) 对于第二个“全选”按钮,如果您希望在单击它时发生某些事情,则必须在您的服务器中放置一个observeEvent : observeEvent(input$all1, { if (is.null(input$che ...