我正在尝试从HTML表单输入中获取文本,然后使用JavaScript和Socket将其发送到服务器端(即python flask),然后将其发送给所有人,并使用包含此内容的
标记为每个人更新页面文字。
它适用于发件人以外的所有客户端,所有先前的
标签由于不明显的原因而被删除。
烧瓶代码:
aus_nz <- function(df, subject = "Math", group = "country") {
group_var <- rlang::syms(group)
df %>%
group_by(!!! group_var) %>%
summarise(ci = list(bootstrap_ci(sex, !! rlang::ensym(subject), weight))) %>%
unnest_wider(ci) %>%
ungroup() # %>% last line needs to be fixed
# mutate(grouped_by = fct_reorder(!!! group_var, avg))
}
JavaScript代码:
@socketio.on("submit channel")
def channel(data):
ch = data["ch"]
channels.append(ch)
emit("channel", {"ch": ch}, broadcast=True)
HTML代码:
document.addEventListener('DOMContentLoaded', () => {
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port);
socket.on('connect', () => {
document.querySelector('#channel').onsubmit = () => {
const ch = document.querySelector('#ch').value;
socket.emit('submit channel', {'ch': ch});
};
});
socket.on('channel', data => {
const p = document.createElement('p');
p.innerHTML = data.ch;
document.querySelector('#channels').append(p);
});
});